ledger-core
Functions
ledger::core::hex Namespace Reference

Functions

std::vector< uint8_t > toByteArray (const std::string &str)
 
std::string toString (const std::vector< uint8_t > &data)
 
uint8_t digitToByte (char c)
 
std::string toString (const std::vector< uint8_t > &data, bool uppercase)
 
char byteToDigit (uint8_t byte, bool uppercase)
 

Detailed Description

Utility functions to deal with hexadecimal encoded string.

Function Documentation

◆ byteToDigit()

char ledger::core::hex::byteToDigit ( uint8_t  ,
bool  uppercase 
)
inline

Turns a single byte (the byte must be lower than 0x10) into a digit.

Exceptions
std::invalid_argumentWhen encountering an invalid character.
Returns

◆ digitToByte()

uint8_t ledger::core::hex::digitToByte ( char  c)
inline

Turns a single digit into its byte value.

Parameters
c
Returns

◆ toByteArray()

std::vector< uint8_t > ledger::core::hex::toByteArray ( const std::string &  hexString)

Decodes the given string into a byte array.

Parameters
hexStringA string of bytes expressed in hexadecimal (e.g. "A0B1").
Exceptions
std::invalid_argumentWhen encountering an invalid character.
Returns

◆ toString() [1/2]

std::string ledger::core::hex::toString ( const std::vector< uint8_t > &  data)

Encodes the given byte array into an hexadecimal string (lowercase).

Parameters
data
Returns

◆ toString() [2/2]

std::string ledger::core::hex::toString ( const std::vector< uint8_t > &  data,
bool  uppercase 
)

Encodes the given byte array into an hexadecimal string.

Parameters
dataA byte array
uppercaseTrue if the output should be expressed in uppercase characters, false otherwise
Returns