aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstate/oid_lookup/oids.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-10-26 02:18:05 +0000
committerlloyd <[email protected]>2008-10-26 02:18:05 +0000
commit17231ebbb95cc45cca50eabc4799c3058fc78ee9 (patch)
tree72b419fcd6a398463ccd0f763dc8bc639ab88b5c /src/libstate/oid_lookup/oids.cpp
parent6f2a68c40d85026da907c8ce5366998f14a99d9c (diff)
Move libstate and selftest out of core/ dir to toplevel
Diffstat (limited to 'src/libstate/oid_lookup/oids.cpp')
-rw-r--r--src/libstate/oid_lookup/oids.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/libstate/oid_lookup/oids.cpp b/src/libstate/oid_lookup/oids.cpp
new file mode 100644
index 000000000..0823625ea
--- /dev/null
+++ b/src/libstate/oid_lookup/oids.cpp
@@ -0,0 +1,74 @@
+/*************************************************
+* OID Registry Source File *
+* (C) 1999-2008 Jack Lloyd *
+*************************************************/
+
+#include <botan/oids.h>
+#include <botan/libstate.h>
+
+namespace Botan {
+
+namespace OIDS {
+
+/*************************************************
+* Register an OID to string mapping *
+*************************************************/
+void add_oid(const OID& oid, const std::string& name)
+ {
+ const std::string oid_str = oid.as_string();
+
+ if(!global_state().is_set("oid2str", oid_str))
+ global_state().set("oid2str", oid_str, name);
+ if(!global_state().is_set("str2oid", name))
+ global_state().set("str2oid", name, oid_str);
+ }
+
+/*************************************************
+* Do an OID to string lookup *
+*************************************************/
+std::string lookup(const OID& oid)
+ {
+ std::string name = global_state().get("oid2str", oid.as_string());
+ if(name == "")
+ return oid.as_string();
+ return name;
+ }
+
+/*************************************************
+* Do a string to OID lookup *
+*************************************************/
+OID lookup(const std::string& name)
+ {
+ std::string value = global_state().get("str2oid", name);
+ if(value != "")
+ return OID(value);
+
+ try
+ {
+ return OID(name);
+ }
+ catch(Exception)
+ {
+ throw Lookup_Error("No object identifier found for " + name);
+ }
+ }
+
+/*************************************************
+* Check to see if an OID exists in the table *
+*************************************************/
+bool have_oid(const std::string& name)
+ {
+ return global_state().is_set("str2oid", name);
+ }
+
+/*************************************************
+* Check to see if an OID exists in the table *
+*************************************************/
+bool name_of(const OID& oid, const std::string& name)
+ {
+ return (oid == lookup(name));
+ }
+
+}
+
+}