This module provides utility functions. It includes functions for converting between byte arrays and hex strings, generating random bytes, and creating salts for password hashing. These utilities are used by the higher-level APIs in the other modules to simplify common tasks and ensure consistent handling of data formats across the library.
Types
Key32 = array[32, uint8]
Nonce24 = array[24, uint8]
RandomBytes = array[16, uint8]
Procs
proc fromHex[N: static int; T](s: string): array[N, T]
- Convert a hex string back to an array of bytes of type T.
proc generateSalt(len: static int = 16): RandomBytes
- Generate a random salt of the given length (default 16 bytes).
proc randomBytes[N: static int](): array[N, uint8]
- Generate N random bytes using urandom. Returns an array of uint8.
proc seqPtr(data: var seq[uint8]): ptr uint8 {.inline, ...raises: [], tags: [], forbids: [].}
proc strPtr(s: string): ptr uint8 {.inline, ...raises: [], tags: [], forbids: [].}
proc toHex[T](v: T): string
- Convert any value to a hex string representation of its bytes.
proc toPtr(data: openArray[byte]): ptr uint8 {.inline, ...raises: [], tags: [], forbids: [].}