# # # patch "ChangeLog" # from [1ba3755df449b5d24ce976b8e0aba397c87a1ca4] # to [0955d776c91093b8260a4f2fd5fb4e1ca23c880a] # # patch "botan/base64.cpp" # from [a7780f8f856946ca1fcaf5a1fa5ee91aaf2504ce] # to [b2a556c12793e219b3a5fb74321d4aa0e03c9404] # # patch "transforms.cc" # from [3d76cc7d7a564fb292d5b579b1a2c9554572a595] # to [549477a83c7953f8df90c86ff16088f3ca7a9cab] # # patch "transforms.hh" # from [fb0db2176375756dbfb28cada6b25e030f8fd70d] # to [fc90e7e7b05c67729b91ed3fd086d09ae2945972] # ============================================================ --- ChangeLog 1ba3755df449b5d24ce976b8e0aba397c87a1ca4 +++ ChangeLog 0955d776c91093b8260a4f2fd5fb4e1ca23c880a @@ -1,3 +1,18 @@ +2007-01-09 Zack Weinberg + + * transforms.hh (xform): Make the generic template produce a + compile error if instantiated. Use standard declarations of + partial specializations for the usable cases of xform, not the g++ + "extern template" extension. + * transforms.cc (xform): Rewrite with a helper template and a + bunch of explicit partial specializations. Put Base64_Decoder and + Hex_Decoder into IGNORE_WS mode (i.e. garbage in their input will + now give an error) + + * botan/base64.cpp (Base64_Decoder::handle_bad_char): Always + ignore equals signs; correct generation of diagnostic message. + Patches from upstream Botan. + 2007-01-09 Matthew Gregan * database.cc: Migrate to new sqlite3_prepare_v2 API. @@ -11,7 +26,7 @@ 2007-01-06 Thomas Keller - * cmd_automate.cc: automate stdio now opens the database + * cmd_automate.cc: automate stdio now opens the database before any command is triggered, this ensures that it early checks for a correct database version ============================================================ --- botan/base64.cpp a7780f8f856946ca1fcaf5a1fa5ee91aaf2504ce +++ botan/base64.cpp b2a556c12793e219b3a5fb74321d4aa0e03c9404 @@ -172,13 +172,15 @@ void Base64_Decoder::handle_bad_char(byt *************************************************/ void Base64_Decoder::handle_bad_char(byte c) { - if(checking == NONE) + if(c == '=' || checking == NONE) return; if((checking == IGNORE_WS) && Charset::is_space(c)) return; - throw Decoding_Error("Base64_Decoder: Invalid base64 character: " + c); + throw Decoding_Error( + std::string("Base64_Decoder: Invalid base64 character '") + char(c) + "'" + ); } /************************************************* ============================================================ --- transforms.cc 3d76cc7d7a564fb292d5b579b1a2c9554572a595 +++ transforms.cc 549477a83c7953f8df90c86ff16088f3ca7a9cab @@ -101,13 +101,14 @@ error_in_transform(Botan::Exception & e) I(false); // can't get here } -// the generic function -template string xform(string const & in) +// worker function for the visible functions below +namespace { +template string xform(XFM * x, string const & in) { string out; try { - Botan::Pipe pipe(new XFM()); + Botan::Pipe pipe(x); pipe.process_msg(in); out = pipe.read_all_as_string(); } @@ -117,15 +118,21 @@ template string xform(stri } return out; } +} -// specialize it -template string xform(string const &); -template string xform(string const &); -template string xform(string const &); -template string xform(string const &); -template string xform(string const &); -template string xform(string const &); +// full specializations for the usable cases of xform() +// use extra error checking in base64 and hex decoding +#define SPECIALIZE_XFORM(T, carg) \ + template<> string xform(string const &in) \ + { return xform(new T(carg), in); } +SPECIALIZE_XFORM(Botan::Base64_Encoder,); +SPECIALIZE_XFORM(Botan::Base64_Decoder, Botan::IGNORE_WS); +SPECIALIZE_XFORM(Botan::Hex_Encoder,); +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 ============================================================ --- transforms.hh fb0db2176375756dbfb28cada6b25e030f8fd70d +++ transforms.hh fc90e7e7b05c67729b91ed3fd086d09ae2945972 @@ -28,19 +28,23 @@ namespace Botan { class Gzip_Decompression; } -#ifdef HAVE_EXTERN_TEMPLATE -#define EXTERN extern -#else -#define EXTERN /* */ -#endif +// this generic template cannot actually be used, except with the +// specializations given below. give a compile error instead of a link +// error. +template std::string xform(std::string const & in) +{ + enum dummy { d = (sizeof(struct xform_must_be_specialized_for_this_type) + == sizeof(XFM)) }; + return in; // avoid warnings about no return statement +} -template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); -EXTERN template std::string xform(std::string const &); +// these specializations of the template are defined in transforms.hh +template<> std::string xform(std::string const &); +template<> std::string xform(std::string const &); +template<> std::string xform(std::string const &); +template<> std::string xform(std::string const &); +template<> std::string xform(std::string const &); +template<> std::string xform(std::string const &); // base64 encoding