On this page:
4.1 ASN.1 Bit String Utilities
bit-string-length
bit-string-ref
4.2 ASN.1 Named Value Utilities
WRAP-NAMES
4.3 ASN.1 Time Utilities
asn1-utc-time->seconds
asn1-generalized-time->seconds

4 ASN.1 Miscellaneous Utilities🔗ℹ

4.1 ASN.1 Bit String Utilities🔗ℹ

Added in version 1.2 of package asn1-lib.

procedure

(bit-string-length bs)  exact-nonnegative-integer?

  bs : bit-string?
Returns the number of bits in bs.

procedure

(bit-string-ref bs index)  boolean?

  bs : bit-string?
  index : exact-nonnegative-integer?
Returns the bit stored in bs at the given index as a boolean. Note that in ASN.1, the first bit of a bit string is stored as the high bit of the first byte.

4.2 ASN.1 Named Value Utilities🔗ℹ

Added in version 1.2 of package asn1-lib.

procedure

(WRAP-NAMES type named-values)  asn1-type?

  type : (or/c ENUMERATED BIT-STRING)
  named-values : (listof (cons/c symbol? any/c))
Wraps type with decode and encode hooks to translate to and from named values.

If type is ENUMERATED, then the corresponding Racket values are symbols from named-values and exact integers for values not in the list.

Examples:
> (define xyz (WRAP-NAMES ENUMERATED '((x . 0) (y . 1) (z . 2))))
> (bytes->asn1 xyz (asn1->bytes ENUMERATED 2))

'z

> (bytes->asn1 xyz (asn1->bytes ENUMERATED 5))

5

If type is BIT-STRING, then the corresponding Racket values are lists of symbols from named-values and exact integers for values not in the list.

Examples:
> (define abc (WRAP-NAMES BIT-STRING '((a . 0) (b . 1) (c . 2))))
> (bytes->asn1 abc (asn1->bytes BIT-STRING (bit-string (bytes #b10100000) 0)))

'(a c)

> (bytes->asn1 abc (asn1->bytes BIT-STRING (bit-string (bytes #b10100010) 0)))

'(a c 6)

4.3 ASN.1 Time Utilities🔗ℹ

Added in version 1.2 of package asn1-lib.

Interprets s as a date and time and returns it as a number of seconds since midnight UTC, January 1, 1970 (like current-seconds, seconds->date, etc). If s omits minutes, seconds, or fractional seconds, they are treated as 0. If s omits the UTC specifier (Z) or timezone offset, the time is interpreted as local time.

The two-digit years of UTCTime are interpreted in the range 1950 to 2049; this is consistent with X.509 but not all other ASN.1 applications.

Examples:
> (asn1-utc-time->seconds "20110220-07")

1604337120

> (asn1-generalized-time->seconds "19700101010203Z")

3723