From 17231ebbb95cc45cca50eabc4799c3058fc78ee9 Mon Sep 17 00:00:00 2001 From: lloyd <lloyd@randombit.net> Date: Sun, 26 Oct 2008 02:18:05 +0000 Subject: Move libstate and selftest out of core/ dir to toplevel --- src/libstate/oid_lookup/info.txt | 15 ++++++++ src/libstate/oid_lookup/oids.cpp | 74 ++++++++++++++++++++++++++++++++++++++++ src/libstate/oid_lookup/oids.h | 56 ++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+) create mode 100644 src/libstate/oid_lookup/info.txt create mode 100644 src/libstate/oid_lookup/oids.cpp create mode 100644 src/libstate/oid_lookup/oids.h (limited to 'src/libstate/oid_lookup') diff --git a/src/libstate/oid_lookup/info.txt b/src/libstate/oid_lookup/info.txt new file mode 100644 index 000000000..b5f4ef21f --- /dev/null +++ b/src/libstate/oid_lookup/info.txt @@ -0,0 +1,15 @@ +realname "OID Lookup" + +load_on dep + +define OID_LOOKUP + +<requires> +#libstate +#asn1 +</requires> + +<add> +oids.cpp +oids.h +</add> 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)); + } + +} + +} diff --git a/src/libstate/oid_lookup/oids.h b/src/libstate/oid_lookup/oids.h new file mode 100644 index 000000000..0df95fb36 --- /dev/null +++ b/src/libstate/oid_lookup/oids.h @@ -0,0 +1,56 @@ +/************************************************* +* OID Registry Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_OIDS_H__ +#define BOTAN_OIDS_H__ + +#include <botan/asn1_oid.h> + +namespace Botan { + +namespace OIDS { + +/** +* Register an OID to string mapping. +* @param oid the oid to register +* @param name the name to be associated with the oid +*/ +BOTAN_DLL void add_oid(const OID& oid, const std::string& name); + +/** +* See if an OID exists in the internal table. +* @param oid the oid to check for +* @return true if the oid is registered +*/ +BOTAN_DLL bool have_oid(const std::string& oid); + +/** +* Resolve an OID +* @param oid the OID to look up +* @return the name associated with this OID +*/ +BOTAN_DLL std::string lookup(const OID& oid); + +/** +* Find the OID to a name. The lookup will be performed in the +* general OID section of the configuration. +* @param name the name to resolve +* @return the OID associated with the specified name +*/ +BOTAN_DLL OID lookup(const std::string& name); + +/** +* Tests whether the specified OID stands for the specified name. +* @param oid the OID to check +* @param name the name to check +* @return true if the specified OID stands for the specified name +*/ +BOTAN_DLL bool name_of(const OID& oid, const std::string& name); + +} + +} + +#endif -- cgit v1.2.3