std/asn1
DER, the ASN.1 encoding of keys and certificates, read and written, for std/publickey and for reading what X.509 holds.
import "std/asn1"
Asn1 value = der_read(data)?
if value.is(ASN1_SEQUENCE) then
print(value.children[0].oid()) // 1.2.840.10045.2.1
end
bytes der = der_write(der_sequence([der_integer(1), der_octet_string(key)]))| Function or method | Result |
|---|---|
der_read(data) |
the value DER data encodes, which must be all of it; an ERROR of kind "invalid_der" for lengths that are not DER's, data cut short, or values nested more than 64 deep |
der_write(value) |
its DER |
der_sequence(children), der_set(children), der_context(n, children) |
constructed values, holding children in the order given (DER sorts a SET's: give them sorted) |
der_integer(n), der_unsigned(bytes), der_octet_string(bytes), der_bit_string(bytes), der_null(), der_utf8(text), der_oid(dotted) |
the universal values |
v.is(tag), v.is_context(n) |
whether it is the universal value of tag (ASN1_INTEGER, ASN1_SEQUENCE, and the other constants), or context-specific [n] |
v.integer(), v.unsigned_bytes(), v.oid(), v.bits(), v.text() |
what an INTEGER, OBJECT IDENTIFIER, BIT STRING, or string holds |
An Asn1 has its class (0 universal, 1 application, 2 context-specific,
3 private), tag, whether it is constructed, its content, and the
children of a constructed value.