diff options
author | Jack Lloyd <[email protected]> | 2016-12-11 15:28:38 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-12-18 16:48:24 -0500 |
commit | f3cb3edb512bdcab498d825886c3366c341b3f78 (patch) | |
tree | 645c73ec295a5a34f25d99903b6d9fa9751e86d3 /src/lib/codec/hex | |
parent | c1dd21253c1f3188ff45d3ad47698efd08235ae8 (diff) |
Convert to using standard uintN_t integer types
Renames a couple of functions for somewhat better name consistency,
eg make_u32bit becomes make_uint32. The old typedefs remain for now
since probably lots of application code uses them.
Diffstat (limited to 'src/lib/codec/hex')
-rw-r--r-- | src/lib/codec/hex/hex.cpp | 38 | ||||
-rw-r--r-- | src/lib/codec/hex/hex.h | 20 |
2 files changed, 29 insertions, 29 deletions
diff --git a/src/lib/codec/hex/hex.cpp b/src/lib/codec/hex/hex.cpp index e47a75cb7..8d8d3ff49 100644 --- a/src/lib/codec/hex/hex.cpp +++ b/src/lib/codec/hex/hex.cpp @@ -12,29 +12,29 @@ namespace Botan { void hex_encode(char output[], - const byte input[], + const uint8_t input[], size_t input_length, bool uppercase) { - static const byte BIN_TO_HEX_UPPER[16] = { + static const uint8_t BIN_TO_HEX_UPPER[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - static const byte BIN_TO_HEX_LOWER[16] = { + static const uint8_t BIN_TO_HEX_LOWER[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - const byte* tbl = uppercase ? BIN_TO_HEX_UPPER : BIN_TO_HEX_LOWER; + const uint8_t* tbl = uppercase ? BIN_TO_HEX_UPPER : BIN_TO_HEX_LOWER; for(size_t i = 0; i != input_length; ++i) { - byte x = input[i]; + uint8_t x = input[i]; output[2*i ] = tbl[(x >> 4) & 0x0F]; output[2*i+1] = tbl[(x ) & 0x0F]; } } -std::string hex_encode(const byte input[], +std::string hex_encode(const uint8_t input[], size_t input_length, bool uppercase) { @@ -46,7 +46,7 @@ std::string hex_encode(const byte input[], return output; } -size_t hex_decode(byte output[], +size_t hex_decode(uint8_t output[], const char input[], size_t input_length, size_t& input_consumed, @@ -61,7 +61,7 @@ size_t hex_decode(byte output[], * Warning: this table assumes ASCII character encodings */ - static const byte HEX_TO_BIN[256] = { + static const uint8_t HEX_TO_BIN[256] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -89,14 +89,14 @@ size_t hex_decode(byte output[], 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - byte* out_ptr = output; + uint8_t* out_ptr = output; bool top_nibble = true; clear_mem(output, input_length / 2); for(size_t i = 0; i != input_length; ++i) { - const byte bin = HEX_TO_BIN[static_cast<byte>(input[i])]; + const uint8_t bin = HEX_TO_BIN[static_cast<uint8_t>(input[i])]; if(bin >= 0x10) { @@ -125,7 +125,7 @@ size_t hex_decode(byte output[], size_t written = (out_ptr - output); /* - * We only got half of a byte at the end; zap the half-written + * We only got half of a uint8_t at the end; zap the half-written * output and mark it as unread */ if(!top_nibble) @@ -137,7 +137,7 @@ size_t hex_decode(byte output[], return written; } -size_t hex_decode(byte output[], +size_t hex_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws) @@ -152,18 +152,18 @@ size_t hex_decode(byte output[], return written; } -size_t hex_decode(byte output[], +size_t hex_decode(uint8_t output[], const std::string& input, bool ignore_ws) { return hex_decode(output, input.data(), input.length(), ignore_ws); } -secure_vector<byte> hex_decode_locked(const char input[], +secure_vector<uint8_t> hex_decode_locked(const char input[], size_t input_length, bool ignore_ws) { - secure_vector<byte> bin(1 + input_length / 2); + secure_vector<uint8_t> bin(1 + input_length / 2); size_t written = hex_decode(bin.data(), input, @@ -174,17 +174,17 @@ secure_vector<byte> hex_decode_locked(const char input[], return bin; } -secure_vector<byte> hex_decode_locked(const std::string& input, +secure_vector<uint8_t> hex_decode_locked(const std::string& input, bool ignore_ws) { return hex_decode_locked(input.data(), input.size(), ignore_ws); } -std::vector<byte> hex_decode(const char input[], +std::vector<uint8_t> hex_decode(const char input[], size_t input_length, bool ignore_ws) { - std::vector<byte> bin(1 + input_length / 2); + std::vector<uint8_t> bin(1 + input_length / 2); size_t written = hex_decode(bin.data(), input, @@ -195,7 +195,7 @@ std::vector<byte> hex_decode(const char input[], return bin; } -std::vector<byte> hex_decode(const std::string& input, +std::vector<uint8_t> hex_decode(const std::string& input, bool ignore_ws) { return hex_decode(input.data(), input.size(), ignore_ws); diff --git a/src/lib/codec/hex/hex.h b/src/lib/codec/hex/hex.h index b524c43f0..2927640e2 100644 --- a/src/lib/codec/hex/hex.h +++ b/src/lib/codec/hex/hex.h @@ -21,7 +21,7 @@ namespace Botan { * @param uppercase should output be upper or lower case? */ void BOTAN_DLL hex_encode(char output[], - const byte input[], + const uint8_t input[], size_t input_length, bool uppercase = true); @@ -32,7 +32,7 @@ void BOTAN_DLL hex_encode(char output[], * @param uppercase should output be upper or lower case? * @return hexadecimal representation of input */ -std::string BOTAN_DLL hex_encode(const byte input[], +std::string BOTAN_DLL hex_encode(const uint8_t input[], size_t input_length, bool uppercase = true); @@ -43,7 +43,7 @@ std::string BOTAN_DLL hex_encode(const byte input[], * @return hexadecimal representation of input */ template<typename Alloc> -std::string hex_encode(const std::vector<byte, Alloc>& input, +std::string hex_encode(const std::vector<uint8_t, Alloc>& input, bool uppercase = true) { return hex_encode(input.data(), input.size(), uppercase); @@ -62,7 +62,7 @@ std::string hex_encode(const std::vector<byte, Alloc>& input, exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL hex_decode(byte output[], +size_t BOTAN_DLL hex_decode(uint8_t output[], const char input[], size_t input_length, size_t& input_consumed, @@ -77,7 +77,7 @@ size_t BOTAN_DLL hex_decode(byte output[], exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL hex_decode(byte output[], +size_t BOTAN_DLL hex_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws = true); @@ -90,7 +90,7 @@ size_t BOTAN_DLL hex_decode(byte output[], exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL hex_decode(byte output[], +size_t BOTAN_DLL hex_decode(uint8_t output[], const std::string& input, bool ignore_ws = true); @@ -102,7 +102,7 @@ size_t BOTAN_DLL hex_decode(byte output[], exception if whitespace is encountered * @return decoded hex output */ -std::vector<byte> BOTAN_DLL +std::vector<uint8_t> BOTAN_DLL hex_decode(const char input[], size_t input_length, bool ignore_ws = true); @@ -114,7 +114,7 @@ hex_decode(const char input[], exception if whitespace is encountered * @return decoded hex output */ -std::vector<byte> BOTAN_DLL +std::vector<uint8_t> BOTAN_DLL hex_decode(const std::string& input, bool ignore_ws = true); @@ -127,7 +127,7 @@ hex_decode(const std::string& input, exception if whitespace is encountered * @return decoded hex output */ -secure_vector<byte> BOTAN_DLL +secure_vector<uint8_t> BOTAN_DLL hex_decode_locked(const char input[], size_t input_length, bool ignore_ws = true); @@ -139,7 +139,7 @@ hex_decode_locked(const char input[], exception if whitespace is encountered * @return decoded hex output */ -secure_vector<byte> BOTAN_DLL +secure_vector<uint8_t> BOTAN_DLL hex_decode_locked(const std::string& input, bool ignore_ws = true); |