Botan: src/libstate/oid_lookup/oids.cpp Source File

Botan 1.10.17

oids.cpp
Go to the documentation of this file.
1 /*
2 * OID Registry
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #include <botan/oids.h>
9 #include <botan/libstate.h>
10
11 namespace Botan {
12
13 namespace OIDS {
14
15 /*
16 * Register an OID to string mapping
17 */
18 void add_oid(const OID& oid, const std::string& name)
19 {
20 const std::string oid_str = oid.as_string();
21
22 if(!global_state().is_set("oid2str", oid_str))
23 global_state().set("oid2str", oid_str, name);
24 if(!global_state().is_set("str2oid", name))
25 global_state().set("str2oid", name, oid_str);
26 }
27
28 /*
29 * Do an OID to string lookup
30 */
31 std::string lookup(const OID& oid)
32 {
33 std::string name = global_state().get("oid2str", oid.as_string());
34 if(name == "")
35 return oid.as_string();
36 return name;
37 }
38
39 /*
40 * Do a string to OID lookup
41 */
42 OID lookup(const std::string& name)
43 {
44 std::string value = global_state().get("str2oid", name);
45 if(value != "")
46 return OID(value);
47
48 try
49 {
50 return OID(name);
51 }
52 catch(...)
53 {
54 throw Lookup_Error("No object identifier found for " + name);
55 }
56 }
57
58 /*
59 * Check to see if an OID exists in the table
60 */
61 bool have_oid(const std::string& name)
62 {
63 return global_state().is_set("str2oid", name);
64 }
65
66 /*
67 * Check to see if an OID exists in the table
68 */
69 bool name_of(const OID& oid, const std::string& name)
70 {
71 return (oid == lookup(name));
72 }
73
74 }
75
76 }
Botan::OIDS::name_of
bool name_of(const OID &oid, const std::string &name)
Definition: oids.cpp:69
Botan::Library_State::is_set
bool is_set(const std::string &section, const std::string &key) const
Definition: libstate.cpp:126
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::OIDS::lookup
std::string lookup(const OID &oid)
Definition: oids.cpp:31
Botan::Library_State::get
std::string get(const std::string &section, const std::string &key) const
Definition: libstate.cpp:114
Botan::Lookup_Error
Definition: exceptn.h:35
Botan
Definition: algo_base.h:14
Botan::OIDS::add_oid
void add_oid(const OID &oid, const std::string &name)
Definition: oids.cpp:18
Botan::Library_State::set
void set(const std::string &section, const std::string &key, const std::string &value, bool overwrite=true)
Definition: libstate.cpp:137
Botan::OIDS::have_oid
bool have_oid(const std::string &name)
Definition: oids.cpp:61
Botan::OID
Definition: asn1_oid.h:20
oid
OID oid
Definition: x509_ext.cpp:446