sodium_hex2bin

Hexadecimal decoding. The sodium_hex2bin() function parses a hexadecimal string hex and converts it to a byte sequence bin. ignore_nullterminated is a string of characters to skip. ignore_nullterminated's last character MUST be '\0' in order to save allocating a new C string and thus be @nogc For example, the string ": \0" allows colons and spaces to be present at any locations in the hexadecimal string. These characters will just be ignored. As a result, "69:FC", "69 FC", "69 : FC" and "69FC" will be valid inputs, and will produce the same output. ignore_nullterminated can be set to null in order to disallow any non-hexadecimal character. bin.length is the maximum number of bytes to put into bin, thus bin has to be sized appropriately in advance as >= hex.length/2, otherwise the function throws. The parser stops when a non-hexadecimal, non-ignored character is found or when bin.length bytes have been written. bin_len is the number of bytes that actually got written into bin. @returns always true (success) and sets pos_hex_non_parsed to the position within hex following the last parsed character. It evaluates in constant time for a given length and format.

  1. alias sodium_hex2bin = deimos.sodium.utils.sodium_hex2bin
  2. bool sodium_hex2bin(ubyte[] bin, char[] hex, string ignore_nullterminated, size_t bin_len, size_t pos_hex_non_parsed)
    @nogc @trusted
    bool
    sodium_hex2bin
    (
    scope ubyte[] bin
    ,
    scope const char[] hex
    ,,
    out size_t bin_len
    ,)

Return Value

Type: bool

true on success, false otherwise

Throws

NoGcException, if bin.length < hex.length/2

See Also

Meta