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
11namespace Botan {
12
13namespace OIDS {
14
15/*
16* Register an OID to string mapping
17*/
18void 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*/
31std::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*/
42OID 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*/
61bool 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*/
69bool name_of(const OID& oid, const std::string& name)
70 {
71 return (oid == lookup(name));
72 }
73
74}
75
76}
bool is_set(const std::string &section, const std::string &key) const
Definition libstate.cpp:126
std::string get(const std::string &section, const std::string &key) const
Definition libstate.cpp:114
void set(const std::string &section, const std::string &key, const std::string &value, bool overwrite=true)
Definition libstate.cpp:137
std::string as_string() const
Definition asn1_oid.cpp:50
OID(const std::string &str="")
Definition asn1_oid.cpp:19
std::string lookup(const OID &oid)
Definition oids.cpp:31
bool name_of(const OID &oid, const std::string &name)
Definition oids.cpp:69
bool have_oid(const std::string &name)
Definition oids.cpp:61
void add_oid(const OID &oid, const std::string &name)
Definition oids.cpp:18
Library_State & global_state()
Lookup_Error(const std::string &err)
Definition exceptn.h:37