Botan 3.4.0
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) {
22 const std::string oid_str = oid.to_string();
23
25
26 auto o2s = m_oid2str.find(oid_str);
27
28 if(o2s == m_oid2str.end()) {
29 m_oid2str.insert(std::make_pair(oid_str, str));
30 } else if(o2s->second != str) {
31 throw Invalid_State("Cannot register two different names to a single OID");
32 }
33
34 auto s2o = m_str2oid.find(std::string(str));
35
36 if(s2o == m_str2oid.end()) {
37 m_str2oid.insert(std::make_pair(str, oid));
38 }
39}
40
41void OID_Map::add_str2oid(const OID& oid, std::string_view str) {
43 if(!m_str2oid.contains(std::string(str))) {
44 m_str2oid.insert(std::make_pair(str, oid));
45 }
46}
47
48void OID_Map::add_oid2str(const OID& oid, std::string_view str) {
49 const std::string oid_str = oid.to_string();
51 if(!m_oid2str.contains(oid_str)) {
52 m_oid2str.insert(std::make_pair(oid_str, str));
53 }
54}
55
56std::string OID_Map::oid2str(const OID& oid) {
57 const std::string oid_str = oid.to_string();
58
60
61 auto i = m_oid2str.find(oid_str);
62 if(i != m_oid2str.end()) {
63 return i->second;
64 }
65
66 return "";
67}
68
69OID OID_Map::str2oid(std::string_view str) {
71 auto i = m_str2oid.find(std::string(str));
72 if(i != m_str2oid.end()) {
73 return i->second;
74 }
75
76 return OID();
77}
78
79} // namespace Botan
std::string oid2str(const OID &oid)
Definition oid_map.cpp:56
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:41
void add_oid2str(const OID &oid, std::string_view str)
Definition oid_map.cpp:48
OID str2oid(std::string_view str)
Definition oid_map.cpp:69
std::string to_string() const
Definition asn1_oid.cpp:108
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:70