diff options
author | lloyd <[email protected]> | 2010-09-03 13:23:45 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-03 13:23:45 +0000 |
commit | cb9a034650620e4d392a2d2f978b687078e5002c (patch) | |
tree | d80914034f7130bc479d3c1bb2ea9f13619a5dd5 /src/sym_algo | |
parent | e201c88a7931bc892c7d608ee9130ceb7c0f2fef (diff) |
Update some callers that were using Hex_Encoder or Hex_Decoder but
really didn't need to.
The ones in symkey and big_code were actually calling accessor
functions to do the encoding themselves without a Pipe (should have
definitely recognized that as a code smell). These versions have
changed semantically with this checkin - previously they would completely
ignore bad inputs, but now invalid inputs are rejected. For instance, you
cannot say
SymmetricKey key("Only some of this is hex, most of it isn't");
And expect to get a valid key formed by filtering out the non-hex
characters and then decoding it. This is almost certainly a good thing.
Also fix include in Botan.xs
Diffstat (limited to 'src/sym_algo')
-rw-r--r-- | src/sym_algo/symkey.cpp | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/src/sym_algo/symkey.cpp b/src/sym_algo/symkey.cpp index 97bd08819..bf2b705d3 100644 --- a/src/sym_algo/symkey.cpp +++ b/src/sym_algo/symkey.cpp @@ -29,16 +29,11 @@ OctetString::OctetString(RandomNumberGenerator& rng, */ void OctetString::change(const std::string& hex_string) { - SecureVector<byte> hex; - for(u32bit j = 0; j != hex_string.length(); ++j) - if(Hex_Decoder::is_valid(hex_string[j])) - hex.append(hex_string[j]); - - if(hex.size() % 2 != 0) - throw Invalid_Argument("OctetString: hex string must encode full bytes"); - bits.resize(hex.size() / 2); - for(u32bit j = 0; j != bits.size(); ++j) - bits[j] = Hex_Decoder::decode(hex.begin() + 2*j); + SecureVector<byte> decoded(hex_string.length() / 2); + + u32bit written = hex_decode(&decoded[0], hex_string); + + bits.set(&decoded[0], written); } /* @@ -88,9 +83,7 @@ void OctetString::set_odd_parity() */ std::string OctetString::as_string() const { - Pipe pipe(new Hex_Encoder); - pipe.process_msg(bits); - return pipe.read_all_as_string(); + return hex_encode(&bits[0], bits.size()); } /* |