veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

codec/der

lib/codec/der.vk

lib/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.

signature
from-list = fn [arr block] bytes

Builds a bytes buffer from an integer element block [0x01 0x02 ...].

signature
u16-be = fn [b bytes, off i64] i64

Reads a 16-bit big-endian integer from b at off.

Executable Example
veko
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 ]
signature
u24-be = fn [b bytes, off i64] i64
signature
u32-be = fn [b bytes, off i64] i64
signature
put-u16-be = fn [mut out bytes, v i64]
signature
put-u24-be = fn [mut out bytes, v i64]
signature
put-u32-be = fn [mut out bytes, v i64]
signature
put-u16-vec = fn [mut out bytes, data bytes]
signature
put-u24-vec = fn [mut out bytes, data bytes]
signature
read-u8 = fn [b bytes, pos i64] any
signature
read-u16 = fn [b bytes, pos i64] any
signature
read-u24 = fn [b bytes, pos i64] any
signature
read-bytes = fn [b bytes, pos i64, n i64] any
signature
read-u16-vec = fn [b bytes, pos i64] any
signature
read-u24-vec = fn [b bytes, pos i64] any
signature
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(...).

signature
decode-all = fn [b bytes] any

Decodes all consecutive DER TLVs inside b (typically the content of a SEQUENCE/SET).

signature
decode-tlv-view = fn [b bytes, pos i64] any

Decodes one DER TLV element without slicing raw.

signature
decode-all-view = fn [b bytes] any
signature
decode-seq-items-view = fn [node map] any
signature
decode-seq-items = fn [node map] any

Decodes an ASN.1 SEQUENCE TLV node into its child TLV block.

signature
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').

signature
decode-int-bytes = fn [content bytes] any

Decodes a positive DER INTEGER into minimal big-endian unsigned magnitude bytes.

signature
decode-int-i64 = fn [content bytes] any

Decodes a non-negative DER INTEGER up to 63 bits into i64.

signature
decode-bitstr = fn [content bytes] any

Decodes a DER BIT STRING content into { unused_bits, data }.

signature
tag-to-enum = fn [tag i64] any

Returns a homoiconic symbol/tag name for common ASN.1 DER tags for parse-block.

signature
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.

signature
encode-len = fn [mut out bytes, n i64]
signature
encode-tlv = fn [tag i64, content bytes] bytes
signature
encode-seq = fn [items block] bytes
signature
encode-int = fn [raw_be bytes] bytes
signature
encode-bitstr = fn [data bytes] bytes