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 | |
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')
-rw-r--r-- | src/lib/codec/base64/base64.cpp | 32 | ||||
-rw-r--r-- | src/lib/codec/base64/base64.h | 16 | ||||
-rw-r--r-- | src/lib/codec/hex/hex.cpp | 38 | ||||
-rw-r--r-- | src/lib/codec/hex/hex.h | 20 |
4 files changed, 53 insertions, 53 deletions
diff --git a/src/lib/codec/base64/base64.cpp b/src/lib/codec/base64/base64.cpp index bd4d36cfa..c854e52b0 100644 --- a/src/lib/codec/base64/base64.cpp +++ b/src/lib/codec/base64/base64.cpp @@ -14,7 +14,7 @@ namespace Botan { namespace { -static const byte BIN_TO_BASE64[64] = { +static const uint8_t BIN_TO_BASE64[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', @@ -22,7 +22,7 @@ static const byte BIN_TO_BASE64[64] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; -void do_base64_encode(char out[4], const byte in[3]) +void do_base64_encode(char out[4], const uint8_t in[3]) { out[0] = BIN_TO_BASE64[((in[0] & 0xFC) >> 2)]; out[1] = BIN_TO_BASE64[((in[0] & 0x03) << 4) | (in[1] >> 4)]; @@ -33,7 +33,7 @@ void do_base64_encode(char out[4], const byte in[3]) } size_t base64_encode(char out[], - const byte in[], + const uint8_t in[], size_t input_length, size_t& input_consumed, bool final_inputs) @@ -54,7 +54,7 @@ size_t base64_encode(char out[], if(final_inputs && input_remaining) { - byte remainder[3] = { 0 }; + uint8_t remainder[3] = { 0 }; for(size_t i = 0; i != input_remaining; ++i) remainder[i] = in[input_consumed + i]; @@ -75,7 +75,7 @@ size_t base64_encode(char out[], return output_produced; } -std::string base64_encode(const byte input[], +std::string base64_encode(const uint8_t input[], size_t input_length) { const size_t output_length = (round_up(input_length, 3) / 3) * 4; @@ -97,7 +97,7 @@ std::string base64_encode(const byte input[], return output; } -size_t base64_decode(byte output[], +size_t base64_decode(uint8_t output[], const char input[], size_t input_length, size_t& input_consumed, @@ -108,7 +108,7 @@ size_t base64_decode(byte output[], * Base64 Decoder Lookup Table * Warning: assumes ASCII encodings */ - static const byte BASE64_TO_BIN[256] = { + static const uint8_t BASE64_TO_BIN[256] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80, 0x80, 0xFF, 0xFF, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -136,8 +136,8 @@ size_t base64_decode(byte output[], 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - byte* out_ptr = output; - byte decode_buf[4]; + uint8_t* out_ptr = output; + uint8_t decode_buf[4]; size_t decode_buf_pos = 0; size_t final_truncate = 0; @@ -145,7 +145,7 @@ size_t base64_decode(byte output[], for(size_t i = 0; i != input_length; ++i) { - const byte bin = BASE64_TO_BIN[static_cast<byte>(input[i])]; + const uint8_t bin = BASE64_TO_BIN[static_cast<uint8_t>(input[i])]; if(bin <= 0x3F) { @@ -194,7 +194,7 @@ size_t base64_decode(byte output[], } while(input_consumed < input_length && - BASE64_TO_BIN[static_cast<byte>(input[input_consumed])] == 0x80) + BASE64_TO_BIN[static_cast<uint8_t>(input[input_consumed])] == 0x80) { ++input_consumed; } @@ -204,7 +204,7 @@ size_t base64_decode(byte output[], return written; } -size_t base64_decode(byte output[], +size_t base64_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws) @@ -219,19 +219,19 @@ size_t base64_decode(byte output[], return written; } -size_t base64_decode(byte output[], +size_t base64_decode(uint8_t output[], const std::string& input, bool ignore_ws) { return base64_decode(output, input.data(), input.length(), ignore_ws); } -secure_vector<byte> base64_decode(const char input[], +secure_vector<uint8_t> base64_decode(const char input[], size_t input_length, bool ignore_ws) { const size_t output_length = (round_up(input_length, 4) * 3) / 4; - secure_vector<byte> bin(output_length); + secure_vector<uint8_t> bin(output_length); size_t written = base64_decode(bin.data(), input, @@ -242,7 +242,7 @@ secure_vector<byte> base64_decode(const char input[], return bin; } -secure_vector<byte> base64_decode(const std::string& input, +secure_vector<uint8_t> base64_decode(const std::string& input, bool ignore_ws) { return base64_decode(input.data(), input.size(), ignore_ws); diff --git a/src/lib/codec/base64/base64.h b/src/lib/codec/base64/base64.h index 92c4dc627..0e78ea3c2 100644 --- a/src/lib/codec/base64/base64.h +++ b/src/lib/codec/base64/base64.h @@ -27,7 +27,7 @@ namespace Botan { * @return number of bytes written to output */ size_t BOTAN_DLL base64_encode(char output[], - const byte input[], + const uint8_t input[], size_t input_length, size_t& input_consumed, bool final_inputs); @@ -38,7 +38,7 @@ size_t BOTAN_DLL base64_encode(char output[], * @param input_length length of input in bytes * @return base64adecimal representation of input */ -std::string BOTAN_DLL base64_encode(const byte input[], +std::string BOTAN_DLL base64_encode(const uint8_t input[], size_t input_length); /** @@ -47,7 +47,7 @@ std::string BOTAN_DLL base64_encode(const byte input[], * @return base64adecimal representation of input */ template<typename Alloc> -std::string base64_encode(const std::vector<byte, Alloc>& input) +std::string base64_encode(const std::vector<uint8_t, Alloc>& input) { return base64_encode(input.data(), input.size()); } @@ -67,7 +67,7 @@ std::string base64_encode(const std::vector<byte, Alloc>& input) exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL base64_decode(byte output[], +size_t BOTAN_DLL base64_decode(uint8_t output[], const char input[], size_t input_length, size_t& input_consumed, @@ -83,7 +83,7 @@ size_t BOTAN_DLL base64_decode(byte output[], exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL base64_decode(byte output[], +size_t BOTAN_DLL base64_decode(uint8_t output[], const char input[], size_t input_length, bool ignore_ws = true); @@ -96,7 +96,7 @@ size_t BOTAN_DLL base64_decode(byte output[], exception if whitespace is encountered * @return number of bytes written to output */ -size_t BOTAN_DLL base64_decode(byte output[], +size_t BOTAN_DLL base64_decode(uint8_t output[], const std::string& input, bool ignore_ws = true); @@ -108,7 +108,7 @@ size_t BOTAN_DLL base64_decode(byte output[], exception if whitespace is encountered * @return decoded base64 output */ -secure_vector<byte> BOTAN_DLL base64_decode(const char input[], +secure_vector<uint8_t> BOTAN_DLL base64_decode(const char input[], size_t input_length, bool ignore_ws = true); @@ -119,7 +119,7 @@ secure_vector<byte> BOTAN_DLL base64_decode(const char input[], exception if whitespace is encountered * @return decoded base64 output */ -secure_vector<byte> BOTAN_DLL base64_decode(const std::string& input, +secure_vector<uint8_t> BOTAN_DLL base64_decode(const std::string& input, bool ignore_ws = true); } 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); |