diff options
author | Jack Lloyd <[email protected]> | 2016-10-22 00:51:13 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-11-03 11:56:50 -0400 |
commit | 62e55f484a7a03e2532875696eb2479a577878e9 (patch) | |
tree | 71c86436d9c3dd2059f7d0024f204e66e535b2b2 /src/lib/asn1/oid_lookup/oids.cpp | |
parent | b1021ca76bb3c47b1b520421ccece38d772e5907 (diff) |
Remove ability to add OIDS at runtime. Remove global OID lock.
OID map is now generated from an input file on an as needed basis.
Just uses a sequence of ifs - simple, fast, and small code size.
Merges oid_lookup sub-module which was already required by asn1 anyway,
so completely non-optional.
Removes @neusdan's nice OID tests since without any runtime adds the
tests are moot.
Diffstat (limited to 'src/lib/asn1/oid_lookup/oids.cpp')
-rw-r--r-- | src/lib/asn1/oid_lookup/oids.cpp | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/src/lib/asn1/oid_lookup/oids.cpp b/src/lib/asn1/oid_lookup/oids.cpp deleted file mode 100644 index 8ee10b75a..000000000 --- a/src/lib/asn1/oid_lookup/oids.cpp +++ /dev/null @@ -1,177 +0,0 @@ -/* -* OID Registry -* (C) 1999-2008,2013 Jack Lloyd -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#include <botan/oids.h> -#include <botan/parsing.h> -#include <botan/mutex.h> -#include <sstream> - -namespace Botan { - -namespace OIDS { - -namespace { - -class OID_Map - { - public: - void add_oid(const OID& oid, const std::string& str) - { - add_str2oid(oid, str); - add_oid2str(oid, str); - } - - void add_str2oid(const OID& oid, const std::string& str) - { - lock_guard_type<mutex_type> lock(m_mutex); - auto i = m_str2oid.find(str); - if(i == m_str2oid.end()) - m_str2oid.insert(std::make_pair(str, oid)); - } - - void add_oid2str(const OID& oid, const std::string& str) - { - lock_guard_type<mutex_type> lock(m_mutex); - auto i = m_oid2str.find(oid); - if(i == m_oid2str.end()) - m_oid2str.insert(std::make_pair(oid, str)); - } - - std::string lookup(const OID& oid) - { - lock_guard_type<mutex_type> lock(m_mutex); - - auto i = m_oid2str.find(oid); - if(i != m_oid2str.end()) - return i->second; - - return ""; - } - - OID lookup(const std::string& str) - { - lock_guard_type<mutex_type> lock(m_mutex); - - auto i = m_str2oid.find(str); - if(i != m_str2oid.end()) - return i->second; - - // Try to parse as plain OID - try - { - return OID(str); - } - catch(...) {} - - throw Lookup_Error("No object identifier found for " + str); - } - - bool have_oid(const std::string& str) - { - lock_guard_type<mutex_type> lock(m_mutex); - return m_str2oid.find(str) != m_str2oid.end(); - } - - static OID_Map& global_registry() - { - static OID_Map g_map; - return g_map; - } - - void read_cfg(std::istream& cfg, const std::string& source); - - private: - - OID_Map() - { - std::istringstream cfg(default_oid_list()); - read_cfg(cfg, "builtin"); - } - - mutex_type m_mutex; - std::map<std::string, OID> m_str2oid; - std::map<OID, std::string> m_oid2str; - }; - -void OID_Map::read_cfg(std::istream& cfg, const std::string& source) - { - lock_guard_type<mutex_type> lock(m_mutex); - - size_t line = 0; - - while(cfg.good()) - { - std::string s; - std::getline(cfg, s); - ++line; - - if(s.empty() || s[0] == '#') - continue; - - s = clean_ws(s.substr(0, s.find('#'))); - - if(s.empty()) - continue; - - auto eq = s.find("="); - - if(eq == std::string::npos || eq == 0 || eq == s.size() - 1) - throw Exception("Bad config line '" + s + "' in " + source + " line " + std::to_string(line)); - - const std::string oid = clean_ws(s.substr(0, eq)); - const std::string name = clean_ws(s.substr(eq + 1, std::string::npos)); - - m_str2oid.insert(std::make_pair(name, OID(oid))); - m_oid2str.insert(std::make_pair(OID(oid), name)); - } - } - -} - -void add_oid(const OID& oid, const std::string& name) - { - OID_Map::global_registry().add_oid(oid, name); - } - -void add_oidstr(const char* oidstr, const char* name) - { - add_oid(OID(oidstr), name); - } - -void add_oid2str(const OID& oid, const std::string& name) - { - OID_Map::global_registry().add_oid2str(oid, name); - } - -void add_str2oid(const OID& oid, const std::string& name) - { - OID_Map::global_registry().add_str2oid(oid, name); - } - -std::string lookup(const OID& oid) - { - return OID_Map::global_registry().lookup(oid); - } - -OID lookup(const std::string& name) - { - return OID_Map::global_registry().lookup(name); - } - -bool have_oid(const std::string& name) - { - return OID_Map::global_registry().have_oid(name); - } - -bool name_of(const OID& oid, const std::string& name) - { - return (oid == lookup(name)); - } - -} - -} |