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

codec/hex

lib/codec/hex.vk

lib/codec/hex.vk Pure-Veko RFC 4648 hexadecimal encoder and decoder. Zero capabilities required.

signature
encode = fn [data bytes] str

Encodes data into a lowercase hexadecimal string.

Executable Example
veko
use [hex = codec/hex]
enc = hex/encode (bytes/from-str 'Veko')
dec = hex/decode enc
if enc != '56656b6f' or (bytes/to-str dec) != 'Veko' [ err 'hex roundtrip' ] else [ .ok ]
signature
encode-upper = fn [data bytes] str

Encodes data into an uppercase hexadecimal string.

signature
decode = fn [s str] bytes

Decodes a hexadecimal string (even length, uppercase or lowercase) into bytes.

signature
b64-encode = fn [data bytes] str

Encodes data into standard RFC 4648 Base64 with '=' padding.

Executable Example
veko
use [hex = codec/hex]
enc = hex/b64-encode (bytes/from-str 'veko')
dec = hex/b64-decode enc
if enc != 'dmVrbw==' or (bytes/to-str dec) != 'veko' [ err 'b64' ] else [ .ok ]
signature
b64url-encode = fn [data bytes] str

Encodes data into RFC 4648 URL-safe Base64 without padding (used by JWT/JWS/OAuth2).

Executable Example
veko
use [hex = codec/hex]
enc = hex/b64url-encode (bytes/from-str 'veko+1/0')
dec = hex/b64url-decode enc
if (str/contains? enc '=') or (bytes/to-str dec) != 'veko+1/0' [ err 'b64url' ] else [ .ok ]
signature
b64-decode = fn [s str] bytes

Decodes standard or URL-safe Base64 (with or without '=' padding) into bytes.

signature
b64url-decode = fn [s str] bytes

Alias for b64-decode accepting unpadded URL-safe Base64 strings.