diff options
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/base64/base64.cpp | 11 | ||||
-rw-r--r-- | src/codec/base64/base64.h | 10 | ||||
-rw-r--r-- | src/codec/hex/hex.cpp | 12 | ||||
-rw-r--r-- | src/codec/hex/hex.h | 14 | ||||
-rw-r--r-- | src/codec/openpgp/openpgp.cpp | 4 | ||||
-rw-r--r-- | src/codec/openpgp/openpgp.h | 4 | ||||
-rw-r--r-- | src/codec/pem/pem.cpp | 21 | ||||
-rw-r--r-- | src/codec/pem/pem.h | 31 |
8 files changed, 54 insertions, 53 deletions
diff --git a/src/codec/base64/base64.cpp b/src/codec/base64/base64.cpp index 6a53a7a9a..719a3e8fa 100644 --- a/src/codec/base64/base64.cpp +++ b/src/codec/base64/base64.cpp @@ -92,11 +92,6 @@ std::string base64_encode(const byte input[], return output; } -std::string base64_encode(const MemoryRegion<byte>& input) - { - return base64_encode(&input[0], input.size()); - } - size_t base64_decode(byte output[], const char input[], size_t input_length, @@ -226,11 +221,11 @@ size_t base64_decode(byte output[], return base64_decode(output, &input[0], input.length(), ignore_ws); } -SecureVector<byte> base64_decode(const char input[], +secure_vector<byte> base64_decode(const char input[], size_t input_length, bool ignore_ws) { - SecureVector<byte> bin((round_up<size_t>(input_length, 4) * 3) / 4); + secure_vector<byte> bin((round_up<size_t>(input_length, 4) * 3) / 4); size_t written = base64_decode(&bin[0], input, @@ -241,7 +236,7 @@ SecureVector<byte> base64_decode(const char input[], return bin; } -SecureVector<byte> base64_decode(const std::string& input, +secure_vector<byte> base64_decode(const std::string& input, bool ignore_ws) { return base64_decode(&input[0], input.size(), ignore_ws); diff --git a/src/codec/base64/base64.h b/src/codec/base64/base64.h index 23a2558bd..9ea4143b7 100644 --- a/src/codec/base64/base64.h +++ b/src/codec/base64/base64.h @@ -46,7 +46,11 @@ std::string BOTAN_DLL base64_encode(const byte input[], * @param input some input * @return base64adecimal representation of input */ -std::string BOTAN_DLL base64_encode(const MemoryRegion<byte>& input); +template<typename Alloc> +std::string base64_encode(const std::vector<byte, Alloc>& input) + { + return base64_encode(&input[0], input.size()); + } /** * Perform base64 decoding @@ -104,7 +108,7 @@ size_t BOTAN_DLL base64_decode(byte output[], exception if whitespace is encountered * @return decoded base64 output */ -SecureVector<byte> BOTAN_DLL base64_decode(const char input[], +secure_vector<byte> BOTAN_DLL base64_decode(const char input[], size_t input_length, bool ignore_ws = true); @@ -115,7 +119,7 @@ SecureVector<byte> BOTAN_DLL base64_decode(const char input[], exception if whitespace is encountered * @return decoded base64 output */ -SecureVector<byte> BOTAN_DLL base64_decode(const std::string& input, +secure_vector<byte> BOTAN_DLL base64_decode(const std::string& input, bool ignore_ws = true); } diff --git a/src/codec/hex/hex.cpp b/src/codec/hex/hex.cpp index 41ba1298d..1fd32e2ed 100644 --- a/src/codec/hex/hex.cpp +++ b/src/codec/hex/hex.cpp @@ -34,12 +34,6 @@ void hex_encode(char output[], } } -std::string hex_encode(const MemoryRegion<byte>& input, - bool uppercase) - { - return hex_encode(&input[0], input.size(), uppercase); - } - std::string hex_encode(const byte input[], size_t input_length, bool uppercase) @@ -165,11 +159,11 @@ size_t hex_decode(byte output[], return hex_decode(output, &input[0], input.length(), ignore_ws); } -SecureVector<byte> hex_decode(const char input[], +secure_vector<byte> hex_decode(const char input[], size_t input_length, bool ignore_ws) { - SecureVector<byte> bin(1 + input_length / 2); + secure_vector<byte> bin(1 + input_length / 2); size_t written = hex_decode(&bin[0], input, @@ -180,7 +174,7 @@ SecureVector<byte> hex_decode(const char input[], return bin; } -SecureVector<byte> hex_decode(const std::string& input, +secure_vector<byte> hex_decode(const std::string& input, bool ignore_ws) { return hex_decode(&input[0], input.size(), ignore_ws); diff --git a/src/codec/hex/hex.h b/src/codec/hex/hex.h index 40930e808..bdb5e5365 100644 --- a/src/codec/hex/hex.h +++ b/src/codec/hex/hex.h @@ -42,8 +42,12 @@ std::string BOTAN_DLL hex_encode(const byte input[], * @param uppercase should output be upper or lower case? * @return hexadecimal representation of input */ -std::string BOTAN_DLL hex_encode(const MemoryRegion<byte>& input, - bool uppercase = true); +template<typename Alloc> +std::string hex_encode(const std::vector<byte, Alloc>& input, + bool uppercase = true) + { + return hex_encode(&input[0], input.size(), uppercase); + } /** * Perform hex decoding @@ -98,7 +102,7 @@ size_t BOTAN_DLL hex_decode(byte output[], exception if whitespace is encountered * @return decoded hex output */ -SecureVector<byte> BOTAN_DLL hex_decode(const char input[], +secure_vector<byte> BOTAN_DLL hex_decode(const char input[], size_t input_length, bool ignore_ws = true); @@ -109,8 +113,8 @@ SecureVector<byte> BOTAN_DLL hex_decode(const char input[], exception if whitespace is encountered * @return decoded hex output */ -SecureVector<byte> BOTAN_DLL hex_decode(const std::string& input, - bool ignore_ws = true); +secure_vector<byte> BOTAN_DLL hex_decode(const std::string& input, + bool ignore_ws = true); } diff --git a/src/codec/openpgp/openpgp.cpp b/src/codec/openpgp/openpgp.cpp index ab9673689..fe6ac6edf 100644 --- a/src/codec/openpgp/openpgp.cpp +++ b/src/codec/openpgp/openpgp.cpp @@ -67,7 +67,7 @@ std::string PGP_encode(const byte input[], size_t length, /* * OpenPGP Base64 decoding */ -SecureVector<byte> PGP_decode(DataSource& source, +secure_vector<byte> PGP_decode(DataSource& source, std::string& label, std::map<std::string, std::string>& headers) { @@ -186,7 +186,7 @@ SecureVector<byte> PGP_decode(DataSource& source, /* * OpenPGP Base64 decoding */ -SecureVector<byte> PGP_decode(DataSource& source, std::string& label) +secure_vector<byte> PGP_decode(DataSource& source, std::string& label) { std::map<std::string, std::string> ignored; return PGP_decode(source, label, ignored); diff --git a/src/codec/openpgp/openpgp.h b/src/codec/openpgp/openpgp.h index 0cd77d53a..de56155f2 100644 --- a/src/codec/openpgp/openpgp.h +++ b/src/codec/openpgp/openpgp.h @@ -42,7 +42,7 @@ BOTAN_DLL std::string PGP_encode( * @param headers is set to any headers * @return decoded output as raw binary */ -BOTAN_DLL SecureVector<byte> PGP_decode( +BOTAN_DLL secure_vector<byte> PGP_decode( DataSource& source, std::string& label, std::map<std::string, std::string>& headers); @@ -52,7 +52,7 @@ BOTAN_DLL SecureVector<byte> PGP_decode( * @param label is set to the human-readable label * @return decoded output as raw binary */ -BOTAN_DLL SecureVector<byte> PGP_decode( +BOTAN_DLL secure_vector<byte> PGP_decode( DataSource& source, std::string& label); diff --git a/src/codec/pem/pem.cpp b/src/codec/pem/pem.cpp index 52a22d8ef..03ec33440 100644 --- a/src/codec/pem/pem.cpp +++ b/src/codec/pem/pem.cpp @@ -28,22 +28,13 @@ std::string encode(const byte der[], size_t length, const std::string& label, } /* -* PEM encode BER/DER-encoded objects -*/ -std::string encode(const MemoryRegion<byte>& data, const std::string& label, - size_t width) - { - return encode(&data[0], data.size(), label, width); - } - -/* * Decode PEM down to raw BER/DER */ -SecureVector<byte> decode_check_label(DataSource& source, +secure_vector<byte> decode_check_label(DataSource& source, const std::string& label_want) { std::string label_got; - SecureVector<byte> ber = decode(source, label_got); + secure_vector<byte> ber = decode(source, label_got); if(label_got != label_want) throw Decoding_Error("PEM: Label mismatch, wanted " + label_want + ", got " + label_got); @@ -53,7 +44,7 @@ SecureVector<byte> decode_check_label(DataSource& source, /* * Decode PEM down to raw BER/DER */ -SecureVector<byte> decode(DataSource& source, std::string& label) +secure_vector<byte> decode(DataSource& source, std::string& label) { const size_t RANDOM_CHAR_LIMIT = 8; @@ -110,14 +101,14 @@ SecureVector<byte> decode(DataSource& source, std::string& label) return base64.read_all(); } -SecureVector<byte> decode_check_label(const std::string& pem, +secure_vector<byte> decode_check_label(const std::string& pem, const std::string& label_want) { DataSource_Memory src(pem); return decode_check_label(src, label_want); } -SecureVector<byte> decode(const std::string& pem, std::string& label) +secure_vector<byte> decode(const std::string& pem, std::string& label) { DataSource_Memory src(pem); return decode(src, label); @@ -131,7 +122,7 @@ bool matches(DataSource& source, const std::string& extra, { const std::string PEM_HEADER = "-----BEGIN " + extra; - SecureVector<byte> search_buf(search_range); + secure_vector<byte> search_buf(search_range); size_t got = source.peek(&search_buf[0], search_buf.size(), 0); if(got < PEM_HEADER.length()) diff --git a/src/codec/pem/pem.h b/src/codec/pem/pem.h index 10267f029..6c33c642d 100644 --- a/src/codec/pem/pem.h +++ b/src/codec/pem/pem.h @@ -17,37 +17,50 @@ namespace PEM_Code { /** * Encode some binary data in PEM format */ -BOTAN_DLL std::string encode(const byte der[], - size_t der_len, +BOTAN_DLL std::string encode(const byte data[], + size_t data_len, const std::string& label, size_t line_width = 64); /** * Encode some binary data in PEM format */ -BOTAN_DLL std::string encode(const MemoryRegion<byte>& der, - const std::string& label, - size_t line_width = 64); +inline std::string encode(const std::vector<byte>& data, + const std::string& label, + size_t line_width = 64) + { + return encode(&data[0], data.size(), label, line_width); + } + +/** +* Encode some binary data in PEM format +*/ +inline std::string encode(const secure_vector<byte>& data, + const std::string& label, + size_t line_width = 64) + { + return encode(&data[0], data.size(), label, line_width); + } /** * Decode PEM data * @param label is set to the PEM label found for later inspection */ -BOTAN_DLL SecureVector<byte> decode(DataSource& pem, +BOTAN_DLL secure_vector<byte> decode(DataSource& pem, std::string& label); /** * Decode PEM data * @param label is set to the PEM label found for later inspection */ -BOTAN_DLL SecureVector<byte> decode(const std::string& pem, +BOTAN_DLL secure_vector<byte> decode(const std::string& pem, std::string& label); /** * Decode PEM data * @param label is what we expect the label to be */ -BOTAN_DLL SecureVector<byte> decode_check_label( +BOTAN_DLL secure_vector<byte> decode_check_label( DataSource& pem, const std::string& label); @@ -55,7 +68,7 @@ BOTAN_DLL SecureVector<byte> decode_check_label( * Decode PEM data * @param label is what we expect the label to be */ -BOTAN_DLL SecureVector<byte> decode_check_label( +BOTAN_DLL secure_vector<byte> decode_check_label( const std::string& pem, const std::string& label); |