codec/der
lib/codec/der.vklib/codec/der.vk
Pure-Veko binary big-endian readers/writers and ASN.1 DER TLV encoder/decoder.
Includes tlv-to-block so decoded DER trees match directly with Veko parse-block.
from-list = fn [arr block] bytes
Builds a bytes buffer from an integer element block [0x01 0x02 ...].
u16-be = fn [b bytes, off i64] i64
Reads a 16-bit big-endian integer from b at off.
use [der = codec/der]
mut b = bytes/with-cap 8
der/put-u16-be mut b 0x0303
der/put-u32-be mut b 0x12345678
if (der/u16-be b 0) != 0x0303 or (der/u32-be b 2) != 0x12345678 [ err 'der be' ] else [ .ok ]
u24-be = fn [b bytes, off i64] i64
u32-be = fn [b bytes, off i64] i64
put-u16-be = fn [mut out bytes, v i64]
put-u24-be = fn [mut out bytes, v i64]
put-u32-be = fn [mut out bytes, v i64]
put-u16-vec = fn [mut out bytes, data bytes]
put-u24-vec = fn [mut out bytes, data bytes]
read-u8 = fn [b bytes, pos i64] any
read-u16 = fn [b bytes, pos i64] any
read-u24 = fn [b bytes, pos i64] any
read-bytes = fn [b bytes, pos i64, n i64] any
read-u16-vec = fn [b bytes, pos i64] any
read-u24-vec = fn [b bytes, pos i64] any
decode-tlv = fn [b bytes, pos i64] any
Decodes one DER TLV element starting at byte offset pos.
Returns { tag, cls, constructed, hdr_len, content, raw, next } or err(...).
decode-all = fn [b bytes] any
Decodes all consecutive DER TLVs inside b (typically the content of a SEQUENCE/SET).
decode-tlv-view = fn [b bytes, pos i64] any
Decodes one DER TLV element without slicing raw.
decode-all-view = fn [b bytes] any
decode-seq-items-view = fn [node map] any
decode-seq-items = fn [node map] any
Decodes an ASN.1 SEQUENCE TLV node into its child TLV block.
decode-oid = fn [content bytes] any
Decodes a DER OBJECT IDENTIFIER content byte slice into dotted decimal text (e.g. '1.2.840.113549.1.1.11').
decode-int-bytes = fn [content bytes] any
Decodes a positive DER INTEGER into minimal big-endian unsigned magnitude bytes.
decode-int-i64 = fn [content bytes] any
Decodes a non-negative DER INTEGER up to 63 bits into i64.
decode-bitstr = fn [content bytes] any
Decodes a DER BIT STRING content into { unused_bits, data }.
tag-to-enum = fn [tag i64] any
Returns a homoiconic symbol/tag name for common ASN.1 DER tags for parse-block.
tlv-to-block = fn [node map] any
Converts a decoded DER TLV tree into a homoiconic Veko block [tag_enum payload]
so downstream code can match DER structures directly using parse-block.
encode-len = fn [mut out bytes, n i64]
encode-tlv = fn [tag i64, content bytes] bytes
encode-seq = fn [items block] bytes
encode-int = fn [raw_be bytes] bytes
encode-bitstr = fn [data bytes] bytes