diff options
-rw-r--r-- | include/charset.h | 13 | ||||
-rw-r--r-- | include/enums.h | 2 | ||||
-rw-r--r-- | include/libstate.h | 5 | ||||
-rw-r--r-- | src/libstate.cpp | 26 |
4 files changed, 46 insertions, 0 deletions
diff --git a/include/charset.h b/include/charset.h index f2fb33e76..a79530f05 100644 --- a/include/charset.h +++ b/include/charset.h @@ -7,11 +7,24 @@ #define BOTAN_CHARSET_H__ #include <botan/types.h> +#include <botan/enums.h> #include <string> namespace Botan { /************************************************* +* Character Set Transcoder Object * +*************************************************/ +class Charset_Transcoder + { + public: + virtual std::string transcode(const std::string&, + Character_Set, Character_Set) const = 0; + + virtual ~Charset_Transcoder() {} + }; + +/************************************************* * Character Set Handling * *************************************************/ bool is_digit(char); diff --git a/include/enums.h b/include/enums.h index 0d3841d68..c03f71004 100644 --- a/include/enums.h +++ b/include/enums.h @@ -92,6 +92,8 @@ enum Cipher_Dir { ENCRYPTION, DECRYPTION }; enum Signature_Format { IEEE_1363, DER_SEQUENCE }; +enum Character_Set { LOCAL_CHARSET, UTF8_CHARSET, LATIN1_CHARSET }; + } #endif diff --git a/include/libstate.h b/include/libstate.h index 340644502..ccc09c224 100644 --- a/include/libstate.h +++ b/include/libstate.h @@ -51,6 +51,10 @@ class Library_State class Mutex* get_mutex(); + void set_transcoder(class Charset_Transcoder*); + std::string transcode(const std::string, + Character_Set, Character_Set) const; + Library_State(class Mutex_Factory*, class Timer*); ~Library_State(); private: @@ -68,6 +72,7 @@ class Library_State std::map<std::string, Allocator*> alloc_factory; mutable Allocator* cached_default_allocator; + class Charset_Transcoder* transcoder; RandomNumberGenerator* rng; std::vector<EntropySource*> entropy_sources; std::vector<class Engine*> engines; diff --git a/src/libstate.cpp b/src/libstate.cpp index 456a4a8dd..581345f76 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -8,6 +8,7 @@ #include <botan/engine.h> #include <botan/mutex.h> #include <botan/timers.h> +#include <botan/charset.h> namespace Botan { @@ -264,6 +265,29 @@ void Library_State::add_engine(Engine* engine) } /************************************************* +* Set the character set transcoder object * +*************************************************/ +void Library_State::set_transcoder(class Charset_Transcoder* transcoder) + { + if(this->transcoder) + delete this->transcoder; + this->transcoder = transcoder; + } + +/************************************************* +* Transcode a string from one charset to another * +*************************************************/ +std::string Library_State::transcode(const std::string str, + Character_Set to, + Character_Set from) const + { + if(!transcoder) + throw Invalid_State("Library_State::transcode: No transcoder set"); + + return transcoder->transcode(str, to, from); + } + +/************************************************* * Library_State Constructor * *************************************************/ Library_State::Library_State(Mutex_Factory* mutex_factory, Timer* timer) @@ -275,6 +299,7 @@ Library_State::Library_State(Mutex_Factory* mutex_factory, Timer* timer) this->mutex_factory = mutex_factory; this->timer = timer; + this->transcoder = 0; locks["settings"] = get_mutex(); locks["allocator"] = get_mutex(); @@ -307,6 +332,7 @@ Library_State::~Library_State() delete j->second; } + delete transcoder; delete mutex_factory; delete timer; |