codec/hex
lib/codec/hex.vklib/codec/hex.vk Pure-Veko RFC 4648 hexadecimal encoder and decoder. Zero capabilities required.
encode = fn [data bytes] str
Encodes data into a lowercase hexadecimal string.
Executable Example
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 ]
decode = fn [s str] bytes
Decodes a hexadecimal string (even length, uppercase or lowercase) into bytes.
b64-encode = fn [data bytes] str
Encodes data into standard RFC 4648 Base64 with '=' padding.
Executable Example
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 ]
b64url-encode = fn [data bytes] str
Encodes data into RFC 4648 URL-safe Base64 without padding (used by JWT/JWS/OAuth2).
Executable Example
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 ]
b64-decode = fn [s str] bytes
Decodes standard or URL-safe Base64 (with or without '=' padding) into bytes.
b64url-decode = fn [s str] bytes
Alias for b64-decode accepting unpadded URL-safe Base64 strings.