From d5f42acd711194c4738859180471b0bd82bc00cb Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 4 Jan 2017 13:40:19 -0500 Subject: Move Data_Store from utils to x509 It is not a general purpose util or something we want applications to use. It is only used by x509 and hopefully will be removed from there soon enough. --- src/lib/utils/datastor/datastor.cpp | 164 ------------------------------------ src/lib/utils/datastor/datastor.h | 57 ------------- src/lib/utils/datastor/info.txt | 0 src/lib/x509/certstor_sql/info.txt | 3 - src/lib/x509/datastor.cpp | 164 ++++++++++++++++++++++++++++++++++++ src/lib/x509/datastor.h | 61 ++++++++++++++ src/lib/x509/info.txt | 1 - 7 files changed, 225 insertions(+), 225 deletions(-) delete mode 100644 src/lib/utils/datastor/datastor.cpp delete mode 100644 src/lib/utils/datastor/datastor.h delete mode 100644 src/lib/utils/datastor/info.txt create mode 100644 src/lib/x509/datastor.cpp create mode 100644 src/lib/x509/datastor.h diff --git a/src/lib/utils/datastor/datastor.cpp b/src/lib/utils/datastor/datastor.cpp deleted file mode 100644 index ae6b1e45c..000000000 --- a/src/lib/utils/datastor/datastor.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* -* Data Store -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include -#include -#include -#include -#include - -namespace Botan { - -/* -* Data_Store Equality Comparison -*/ -bool Data_Store::operator==(const Data_Store& other) const - { - return (m_contents == other.m_contents); - } - -/* -* Check if this key has at least one value -*/ -bool Data_Store::has_value(const std::string& key) const - { - return (m_contents.lower_bound(key) != m_contents.end()); - } - -/* -* Search based on an arbitrary predicate -*/ -std::multimap Data_Store::search_for( - std::function predicate) const - { - std::multimap out; - - for(auto i = m_contents.begin(); i != m_contents.end(); ++i) - if(predicate(i->first, i->second)) - out.insert(std::make_pair(i->first, i->second)); - - return out; - } - -/* -* Search based on key equality -*/ -std::vector Data_Store::get(const std::string& looking_for) const - { - std::vector out; - auto range = m_contents.equal_range(looking_for); - for(auto i = range.first; i != range.second; ++i) - out.push_back(i->second); - return out; - } - -/* -* Get a single atom -*/ -std::string Data_Store::get1(const std::string& key) const - { - std::vector vals = get(key); - - if(vals.empty()) - throw Invalid_State("Data_Store::get1: No values set for " + key); - if(vals.size() > 1) - throw Invalid_State("Data_Store::get1: More than one value for " + key); - - return vals[0]; - } - -std::string Data_Store::get1(const std::string& key, - const std::string& default_value) const - { - std::vector vals = get(key); - - if(vals.size() > 1) - throw Invalid_State("Data_Store::get1: More than one value for " + key); - - if(vals.empty()) - return default_value; - - return vals[0]; - } - -/* -* Get a single std::vector atom -*/ -std::vector -Data_Store::get1_memvec(const std::string& key) const - { - std::vector vals = get(key); - - if(vals.empty()) - return std::vector(); - - if(vals.size() > 1) - throw Invalid_State("Data_Store::get1_memvec: Multiple values for " + - key); - - return hex_decode(vals[0]); - } - -/* -* Get a single uint32_t atom -*/ -uint32_t Data_Store::get1_uint32(const std::string& key, - uint32_t default_val) const - { - std::vector vals = get(key); - - if(vals.empty()) - return default_val; - else if(vals.size() > 1) - throw Invalid_State("Data_Store::get1_uint32: Multiple values for " + key); - - return to_u32bit(vals[0]); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, const std::string& val) - { - multimap_insert(m_contents, key, val); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, uint32_t val) - { - add(key, std::to_string(val)); - } - -/* -* Insert a single key and value -*/ -void Data_Store::add(const std::string& key, const secure_vector& val) - { - add(key, hex_encode(val.data(), val.size())); - } - -void Data_Store::add(const std::string& key, const std::vector& val) - { - add(key, hex_encode(val.data(), val.size())); - } - -/* -* Insert a mapping of key/value pairs -*/ -void Data_Store::add(const std::multimap& in) - { - std::multimap::const_iterator i = in.begin(); - while(i != in.end()) - { - m_contents.insert(*i); - ++i; - } - } - -} diff --git a/src/lib/utils/datastor/datastor.h b/src/lib/utils/datastor/datastor.h deleted file mode 100644 index ee9ef219a..000000000 --- a/src/lib/utils/datastor/datastor.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Data Store -* (C) 1999-2007 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_DATA_STORE_H__ -#define BOTAN_DATA_STORE_H__ - -#include -#include -#include -#include -#include -#include - -namespace Botan { - -/** -* Data Store -*/ -class BOTAN_DLL Data_Store - { - public: - /** - * A search function - */ - bool operator==(const Data_Store&) const; - - std::multimap search_for( - std::function predicate) const; - - std::vector get(const std::string&) const; - - std::string get1(const std::string& key) const; - - std::string get1(const std::string& key, - const std::string& default_value) const; - - std::vector get1_memvec(const std::string&) const; - uint32_t get1_uint32(const std::string&, uint32_t = 0) const; - - bool has_value(const std::string&) const; - - void add(const std::multimap&); - void add(const std::string&, const std::string&); - void add(const std::string&, uint32_t); - void add(const std::string&, const secure_vector&); - void add(const std::string&, const std::vector&); - private: - std::multimap m_contents; - }; - -} - -#endif diff --git a/src/lib/utils/datastor/info.txt b/src/lib/utils/datastor/info.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/lib/x509/certstor_sql/info.txt b/src/lib/x509/certstor_sql/info.txt index cfdd521a2..619784e70 100644 --- a/src/lib/x509/certstor_sql/info.txt +++ b/src/lib/x509/certstor_sql/info.txt @@ -1,5 +1,2 @@ define CERTSTOR_SQL 20160818 - -datastor - diff --git a/src/lib/x509/datastor.cpp b/src/lib/x509/datastor.cpp new file mode 100644 index 000000000..ae6b1e45c --- /dev/null +++ b/src/lib/x509/datastor.cpp @@ -0,0 +1,164 @@ +/* +* Data Store +* (C) 1999-2007 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#include +#include +#include +#include +#include + +namespace Botan { + +/* +* Data_Store Equality Comparison +*/ +bool Data_Store::operator==(const Data_Store& other) const + { + return (m_contents == other.m_contents); + } + +/* +* Check if this key has at least one value +*/ +bool Data_Store::has_value(const std::string& key) const + { + return (m_contents.lower_bound(key) != m_contents.end()); + } + +/* +* Search based on an arbitrary predicate +*/ +std::multimap Data_Store::search_for( + std::function predicate) const + { + std::multimap out; + + for(auto i = m_contents.begin(); i != m_contents.end(); ++i) + if(predicate(i->first, i->second)) + out.insert(std::make_pair(i->first, i->second)); + + return out; + } + +/* +* Search based on key equality +*/ +std::vector Data_Store::get(const std::string& looking_for) const + { + std::vector out; + auto range = m_contents.equal_range(looking_for); + for(auto i = range.first; i != range.second; ++i) + out.push_back(i->second); + return out; + } + +/* +* Get a single atom +*/ +std::string Data_Store::get1(const std::string& key) const + { + std::vector vals = get(key); + + if(vals.empty()) + throw Invalid_State("Data_Store::get1: No values set for " + key); + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1: More than one value for " + key); + + return vals[0]; + } + +std::string Data_Store::get1(const std::string& key, + const std::string& default_value) const + { + std::vector vals = get(key); + + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1: More than one value for " + key); + + if(vals.empty()) + return default_value; + + return vals[0]; + } + +/* +* Get a single std::vector atom +*/ +std::vector +Data_Store::get1_memvec(const std::string& key) const + { + std::vector vals = get(key); + + if(vals.empty()) + return std::vector(); + + if(vals.size() > 1) + throw Invalid_State("Data_Store::get1_memvec: Multiple values for " + + key); + + return hex_decode(vals[0]); + } + +/* +* Get a single uint32_t atom +*/ +uint32_t Data_Store::get1_uint32(const std::string& key, + uint32_t default_val) const + { + std::vector vals = get(key); + + if(vals.empty()) + return default_val; + else if(vals.size() > 1) + throw Invalid_State("Data_Store::get1_uint32: Multiple values for " + key); + + return to_u32bit(vals[0]); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, const std::string& val) + { + multimap_insert(m_contents, key, val); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, uint32_t val) + { + add(key, std::to_string(val)); + } + +/* +* Insert a single key and value +*/ +void Data_Store::add(const std::string& key, const secure_vector& val) + { + add(key, hex_encode(val.data(), val.size())); + } + +void Data_Store::add(const std::string& key, const std::vector& val) + { + add(key, hex_encode(val.data(), val.size())); + } + +/* +* Insert a mapping of key/value pairs +*/ +void Data_Store::add(const std::multimap& in) + { + std::multimap::const_iterator i = in.begin(); + while(i != in.end()) + { + m_contents.insert(*i); + ++i; + } + } + +} diff --git a/src/lib/x509/datastor.h b/src/lib/x509/datastor.h new file mode 100644 index 000000000..e5e8b3f1b --- /dev/null +++ b/src/lib/x509/datastor.h @@ -0,0 +1,61 @@ +/* +* Data Store +* (C) 1999-2007 Jack Lloyd +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_DATA_STORE_H__ +#define BOTAN_DATA_STORE_H__ + +#include +#include +#include +#include +#include +#include + +namespace Botan { + +/** +* Data Store +* +* This class is used internally by the library, and exposed for ABI +* reasons. There is no reason for applications to use this type directly. +* It will be removed in a future major release. +*/ +class BOTAN_DLL Data_Store + { + public: + /** + * A search function + */ + bool operator==(const Data_Store&) const; + + std::multimap search_for( + std::function predicate) const; + + std::vector get(const std::string&) const; + + std::string get1(const std::string& key) const; + + std::string get1(const std::string& key, + const std::string& default_value) const; + + std::vector get1_memvec(const std::string&) const; + uint32_t get1_uint32(const std::string&, uint32_t = 0) const; + + bool has_value(const std::string&) const; + + void add(const std::multimap&); + void add(const std::string&, const std::string&); + void add(const std::string&, uint32_t); + void add(const std::string&, const secure_vector&); + void add(const std::string&, const std::vector&); + private: + std::multimap m_contents; + }; + +} + +#endif diff --git a/src/lib/x509/info.txt b/src/lib/x509/info.txt index 7e6afc5ad..b1a0ab414 100644 --- a/src/lib/x509/info.txt +++ b/src/lib/x509/info.txt @@ -3,7 +3,6 @@ define OCSP 20161118 asn1 -datastor pubkey sha1 -- cgit v1.2.3