YubikeyOTP.ModHex (YubikeyOTP v0.2.1) View Source

Implementation of ModHex encoding and decoding.

Link to this section Summary

Functions

Decodes the given modhex into a binary string.

Decodes the given modhex into a binary string.

Encodes the binary string to modhex.

Determines whether the given string is hexadecimal.

Converts the given hexadecimal string to modhex.

Determines whether the given string is modhex.

The digits in modhex

Converts the given modhex string to hexadecimal.

Link to this section Functions

Specs

decode(string :: binary()) :: {:ok, binary()} | :error

Decodes the given modhex into a binary string.

An ArgumentError exception is raised if the value is not modhex.

Examples

iex> YubikeyOTP.ModHex.decode("jjnkec")
{:ok, <<0x88, 0xb9, 0x30>>}

iex> YubikeyOTP.ModHex.decode("nope")
:error

Specs

decode!(string :: binary()) :: binary()

Decodes the given modhex into a binary string.

An ArgumentError exception is raised if the value is not modhex.

Examples

iex> YubikeyOTP.ModHex.decode!("jjnkec")
<<0x88, 0xb9, 0x30>>

Specs

encode(string :: binary()) :: binary()

Encodes the binary string to modhex.

Examples

iex> YubikeyOTP.ModHex.encode(<<0x88, 0xb9, 0x30>>)
"jjnkec"

Specs

hex?(string :: binary()) :: boolean()

Determines whether the given string is hexadecimal.

Examples

iex> YubikeyOTP.ModHex.hex?("666f6F626172")
true

iex> YubikeyOTP.ModHex.hex?("nope")
false

Specs

hex_to_modhex!(string :: binary()) :: binary()

Converts the given hexadecimal string to modhex.

An ArgumentError exception is raised if the value is not hex.

Examples

iex> YubikeyOTP.ModHex.hex_to_modhex!("88b930")
"jjnkec"

iex> YubikeyOTP.ModHex.hex_to_modhex!("88B930")
"jjnkec"

Specs

modhex?(string :: binary()) :: boolean()

Determines whether the given string is modhex.

Examples

iex> YubikeyOTP.ModHex.modhex?("jjnkec")
true

iex> YubikeyOTP.ModHex.modhex?("nope")
false
Link to this macro

modhex_digits()

View Source (macro)

The digits in modhex

Specs

to_hex!(string :: binary()) :: binary()

Converts the given modhex string to hexadecimal.

An ArgumentError exception is raised if the value is not modhex.

Examples

iex> YubikeyOTP.ModHex.to_hex!("jjnkec")
"88b930"