No matching definitions.

secret/hex

src/secret/hex.tur

constant-time hex codecs whose output is itself a Secret.

Since: 0.1.0

defn

hex-encode-raw!

(hex-encode-raw! [p ptr<void> n : int out ptr<void>] :)

write 2*n lowercase hex chars for n bytes at `p`.

psource bytes
nsource length
outdestination, at least 2*n bytes (no NUL is written)

The number of characters written (2*n). It returns a count rather than `:void` so it can be sequenced in a `let` binding list -- binding a :void call emits `void x = ...` and fails the C compile.

(hex-encode-raw! key 32 buf)   ; => 64

Since: 0.1.0

defn

hex-decode-raw!

(hex-decode-raw! [p ptr<void> n : int out ptr<void>] :)

decode 2*n hex chars at `p` into n bytes at `out`.

psource hex characters
nnumber of BYTES to produce (source must hold 2*n characters)
outdestination, at least n bytes

true when every character was a valid hex digit. On false the destination is wiped rather than left holding a partial decode.

(hex-decode-raw! "ff00" 2 buf)   ; => true, buf = {0xff, 0x00}

Since: 0.1.0

defn

secret->hex

(secret->hex [^borrow s : Secret] :)

lowercase hex of a borrowed secret, as a new Secret.

sthe secret, borrowed (not consumed)

(Result Secret cstr) -- ok carries a 2n-byte Secret of hex characters (not NUL-terminated).

(let [r (secret->hex k)]
    (if (ok? r) (ok-val r) ...))

Since: 0.1.0

defn

secret-of-hex

(secret-of-hex [c : cstr] :)

decode a hex string into a new Secret.

chex characters, upper or lower case, even length

(Result Secret cstr) -- ok carries the decoded bytes; err on an odd length, an empty string, or any non-hex character.

(secret-of-hex "deadbeef")   ; => ok, a 4-byte Secret

Since: 0.1.0

Internal definitions
hex-wipe-raw!-- local wipe shim so hex-decode-raw! can clear a failed
cstr-len-- byte length of a NUL-terminated string.
cstr-ptr-- view a cstr as a raw byte pointer.
encode-then-wrap-- encode into scratch, copy into a Secret, free scratch.
decode-then-wrap-- decode into scratch, copy into a Secret, free scratch.
wrap-decoded-- copy n decoded bytes into a Secret, then free the scratch.
fail-decoded-- release the scratch and report a malformed input.