aboutsummaryrefslogtreecommitdiffstats
path: root/src/codec
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-05-26 14:25:05 +0000
committerlloyd <[email protected]>2012-05-26 14:25:05 +0000
commitc13a1a1a961f508c06ea9e1f04cb0652b169e32e (patch)
tree0d64f719cd1aa1d0947cb379b0f331c3cd5814ea /src/codec
parent9031c9098d0bf5416251fbba9e84246cce8be1f5 (diff)
Plain hex_decode now returns a std::vector, use hex_decode_locked to
get a secure_vector.
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/hex/hex.cpp31
-rw-r--r--src/codec/hex/hex.h37
2 files changed, 58 insertions, 10 deletions
diff --git a/src/codec/hex/hex.cpp b/src/codec/hex/hex.cpp
index 1fd32e2ed..104125894 100644
--- a/src/codec/hex/hex.cpp
+++ b/src/codec/hex/hex.cpp
@@ -159,9 +159,9 @@ size_t hex_decode(byte output[],
return hex_decode(output, &input[0], input.length(), ignore_ws);
}
-secure_vector<byte> hex_decode(const char input[],
- size_t input_length,
- bool ignore_ws)
+secure_vector<byte> hex_decode_locked(const char input[],
+ size_t input_length,
+ bool ignore_ws)
{
secure_vector<byte> bin(1 + input_length / 2);
@@ -174,8 +174,29 @@ secure_vector<byte> hex_decode(const char input[],
return bin;
}
-secure_vector<byte> hex_decode(const std::string& input,
- bool ignore_ws)
+secure_vector<byte> hex_decode_locked(const std::string& input,
+ bool ignore_ws)
+ {
+ return hex_decode_locked(&input[0], input.size(), ignore_ws);
+ }
+
+std::vector<byte> hex_decode(const char input[],
+ size_t input_length,
+ bool ignore_ws)
+ {
+ std::vector<byte> bin(1 + input_length / 2);
+
+ size_t written = hex_decode(&bin[0],
+ input,
+ input_length,
+ ignore_ws);
+
+ bin.resize(written);
+ return bin;
+ }
+
+std::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 bdb5e5365..a64a6c8df 100644
--- a/src/codec/hex/hex.h
+++ b/src/codec/hex/hex.h
@@ -102,9 +102,10 @@ size_t BOTAN_DLL hex_decode(byte output[],
exception if whitespace is encountered
* @return decoded hex output
*/
-secure_vector<byte> BOTAN_DLL hex_decode(const char input[],
- size_t input_length,
- bool ignore_ws = true);
+std::vector<byte> BOTAN_DLL
+hex_decode(const char input[],
+ size_t input_length,
+ bool ignore_ws = true);
/**
* Perform hex decoding
@@ -113,8 +114,34 @@ secure_vector<byte> BOTAN_DLL hex_decode(const char input[],
exception if whitespace is encountered
* @return decoded hex output
*/
-secure_vector<byte> BOTAN_DLL hex_decode(const std::string& input,
- bool ignore_ws = true);
+std::vector<byte> BOTAN_DLL
+hex_decode(const std::string& input,
+ bool ignore_ws = true);
+
+
+/**
+* Perform hex decoding
+* @param input some hex input
+* @param input_length the length of input in bytes
+* @param ignore_ws ignore whitespace on input; if false, throw an
+ exception if whitespace is encountered
+* @return decoded hex output
+*/
+secure_vector<byte> BOTAN_DLL
+hex_decode_locked(const char input[],
+ size_t input_length,
+ bool ignore_ws = true);
+
+/**
+* Perform hex decoding
+* @param input some hex input
+* @param ignore_ws ignore whitespace on input; if false, throw an
+ exception if whitespace is encountered
+* @return decoded hex output
+*/
+secure_vector<byte> BOTAN_DLL
+hex_decode_locked(const std::string& input,
+ bool ignore_ws = true);
}