# # # patch "ChangeLog" # from [ed7ebe46ea288926f27d9dae195dbb1b07100b34] # to [59db5fcab0f06ebaac0b4b1176272b3a568532ce] # # patch "transforms.cc" # from [549477a83c7953f8df90c86ff16088f3ca7a9cab] # to [ff33922197e5107a27eb3cf106a989dfee2732a0] # # patch "transforms.hh" # from [fc90e7e7b05c67729b91ed3fd086d09ae2945972] # to [4294da861e7cc7780ab744745edf10c898ad8ea3] # ============================================================ --- ChangeLog ed7ebe46ea288926f27d9dae195dbb1b07100b34 +++ ChangeLog 59db5fcab0f06ebaac0b4b1176272b3a568532ce @@ -1,3 +1,15 @@ +2007-01-13 Zack Weinberg + + * transforms.cc (encode_hexenc_inner, encode_hexenc, decode_hex_char) + (decode_hexenc_inner, decode_hexenc): Delete. + (xform): Request lowercase output. + (calculate_ident): Put a Botan::Hex_Encoder in the pipeline rather + than doing a separate call to encode_hexenc. Delete unused overload. + * transforms.hh (encode_hexenc, decode_hexenc): Define in terms of + appropriate xform<> instantiations. + (pack, unpack): Delete unnecessary extern-template declarations. + (calculate_ident): Delete unused overload. + 2007-01-12 Zack Weinberg * tests/db_migrate_on_bad_schema: Rename to schema_migration_bad_schema. ============================================================ --- transforms.cc 549477a83c7953f8df90c86ff16088f3ca7a9cab +++ transforms.cc ff33922197e5107a27eb3cf106a989dfee2732a0 @@ -128,87 +128,11 @@ SPECIALIZE_XFORM(Botan::Base64_Decoder, SPECIALIZE_XFORM(Botan::Base64_Encoder,); SPECIALIZE_XFORM(Botan::Base64_Decoder, Botan::IGNORE_WS); -SPECIALIZE_XFORM(Botan::Hex_Encoder,); +SPECIALIZE_XFORM(Botan::Hex_Encoder, Botan::Hex_Encoder::Lowercase); SPECIALIZE_XFORM(Botan::Hex_Decoder, Botan::IGNORE_WS); SPECIALIZE_XFORM(Botan::Gzip_Compression,); SPECIALIZE_XFORM(Botan::Gzip_Decompression,); -// for use in hexenc encoding - -static inline void -encode_hexenc_inner(string::const_iterator i, - string::const_iterator end, - char *out) -{ - static char const *tab = "0123456789abcdef"; - for (; i != end; ++i) - { - *out++ = tab[(*i >> 4) & 0xf]; - *out++ = tab[*i & 0xf]; - } -} - - -string encode_hexenc(string const & in) -{ - if (LIKELY(in.size() == constants::idlen / 2)) - { - char buf[constants::idlen]; - encode_hexenc_inner(in.begin(), in.end(), buf); - return string(buf, constants::idlen); - } - else - { - scoped_array buf(new char[in.size() * 2]); - encode_hexenc_inner(in.begin(), in.end(), buf.get()); - return string(buf.get(), in.size() *2); - } -} - -static inline char -decode_hex_char(char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - else - { - I(c >= 'a' && c <= 'f'); - return c - 'a' + 10; - } -} - -static inline void -decode_hexenc_inner(string::const_iterator i, - string::const_iterator end, - char *out) -{ - for (; i != end; ++i) - { - char t = decode_hex_char(*i++); - t <<= 4; - t |= decode_hex_char(*i); - *out++ = t; - } -} - -string decode_hexenc(string const & in) -{ - - I(in.size() % 2 == 0); - if (LIKELY(in.size() == constants::idlen)) - { - char buf[constants::idlen / 2]; - decode_hexenc_inner(in.begin(), in.end(), buf); - return string(buf, constants::idlen / 2); - } - else - { - scoped_array buf(new char[in.size() / 2]); - decode_hexenc_inner(in.begin(), in.end(), buf.get()); - return string(buf.get(), in.size() / 2); - } -} - template void pack(T const & in, base64< gzip > & out) { @@ -283,34 +207,20 @@ calculate_ident(data const & dat, calculate_ident(data const & dat, hexenc & ident) { - string s; try { - Botan::Pipe p(new Botan::Hash_Filter("SHA-160")); + Botan::Pipe p(new Botan::Hash_Filter("SHA-160"), + new Botan::Hex_Encoder(Botan::Hex_Encoder::Lowercase)); p.process_msg(dat()); - s = p.read_all_as_string(); + ident = p.read_all_as_string(); } catch (Botan::Exception & e) { error_in_transform(e); } - - id ident_decoded(s); - encode_hexenc(ident_decoded, ident); } void -calculate_ident(base64< gzip > const & dat, - hexenc & ident) -{ - gzip data_decoded; - data data_decompressed; - decode_base64(dat, data_decoded); - decode_gzip(data_decoded, data_decompressed); - calculate_ident(data_decompressed, ident); -} - -void calculate_ident(file_data const & dat, file_id & ident) { ============================================================ --- transforms.hh fc90e7e7b05c67729b91ed3fd086d09ae2945972 +++ transforms.hh 4294da861e7cc7780ab744745edf10c898ad8ea3 @@ -59,16 +59,18 @@ void decode_base64(base64 const & in, // hex encoding -std::string encode_hexenc(std::string const & in); -std::string decode_hexenc(std::string const & in); +template +void encode_hexenc(T const & in, hexenc & out) +{ out = xform(in()); } template void decode_hexenc(hexenc const & in, T & out) -{ out = decode_hexenc(in()); } +{ out = xform(in()); } -template -void encode_hexenc(T const & in, hexenc & out) -{ out = encode_hexenc(in()); } +inline std::string encode_hexenc(std::string const & in) +{ return xform(in); } +inline std::string decode_hexenc(std::string const & in) +{ return xform(in); } // gzip @@ -87,16 +89,13 @@ void encode_gzip(std::string const & in, { out = xform(in); } // both at once (this is relatively common) +// these are usable for T = data and T = delta template void pack(T const & in, base64< gzip > & out); -EXTERN template void pack(data const &, base64< gzip > &); -EXTERN template void pack(delta const &, base64< gzip > &); template void unpack(base64< gzip > const & in, T & out); -EXTERN template void unpack(base64< gzip > const &, data &); -EXTERN template void unpack(base64< gzip > const &, delta &); // diffing and patching @@ -115,9 +114,6 @@ void calculate_ident(data const & dat, void calculate_ident(data const & dat, hexenc & ident); -void calculate_ident(base64< gzip > const & dat, - hexenc & ident); - void calculate_ident(file_data const & dat, file_id & ident);