Botan 3.7.1
Crypto and TLS for C&
oid_map.cpp
Go to the documentation of this file.
1/*
2* (C) 2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/oid_map.h>
8
9namespace Botan {
10
11OID_Map::OID_Map() {
12 m_str2oid = OID_Map::load_str2oid_map();
13 m_oid2str = OID_Map::load_oid2str_map();
14}
15
17 static OID_Map g_map;
18 return g_map;
19}
20
21void OID_Map::add_oid(const OID& oid, std::string_view str) {
23
24 auto o2s = m_oid2str.find(oid);
25
26 if(o2s == m_oid2str.end()) {
27 m_oid2str.insert(std::make_pair(oid, str));
28 } else if(o2s->second != str) {
29 throw Invalid_State("Cannot register two different names to a single OID");
30 }
31
32 auto s2o = m_str2oid.find(std::string(str));
33
34 if(s2o == m_str2oid.end()) {
35 m_str2oid.insert(std::make_pair(str, oid));
36 }
37}
38
39void OID_Map::add_str2oid(const OID& oid, std::string_view str) {
41 if(!m_str2oid.contains(std::string(str))) {
42 m_str2oid.insert(std::make_pair(str, oid));
43 }
44}
45
46void OID_Map::add_oid2str(const OID& oid, std::string_view str) {
48 if(!m_oid2str.contains(oid)) {
49 m_oid2str.insert(std::make_pair(oid, str));
50 }
51}
52
53std::string OID_Map::oid2str(const OID& oid) {
55
56 auto i = m_oid2str.find(oid);
57 if(i != m_oid2str.end()) {
58 return i->second;
59 }
60
61 return "";
62}
63
64OID OID_Map::str2oid(std::string_view str) {
66 auto i = m_str2oid.find(std::string(str));
67 if(i != m_str2oid.end()) {
68 return i->second;
69 }
70
71 return OID();
72}
73
74} // namespace Botan
std::string oid2str(const OID &oid)
Definition oid_map.cpp:53
void add_oid(const OID &oid, std::string_view str)
Definition oid_map.cpp:21
static OID_Map & global_registry()
Definition oid_map.cpp:16
void add_str2oid(const OID &oid, std::string_view str)
Definition oid_map.cpp:39
void add_oid2str(const OID &oid, std::string_view str)
Definition oid_map.cpp:46
OID str2oid(std::string_view str)
Definition oid_map.cpp:64
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:70