Botan 3.13.0
Crypto and TLS for C&
Botan::OID_Map Class Referencefinal

#include <oid_map.h>

Public Member Functions

void add_oid (const OID &oid, std::string_view str)
void add_oid2str (const OID &oid, std::string_view str)
void add_str2oid (const OID &oid, std::string_view str)
std::optional< std::string > oid2str (const OID &oid)
OID str2oid (std::string_view str)

Static Public Member Functions

static OID_Map & global_registry ()

Detailed Description

Definition at line 19 of file oid_map.h.

Member Function Documentation

◆ add_oid()

void Botan::OID_Map::add_oid ( const OID & oid,
std::string_view str )

Definition at line 21 of file oid_map.cpp.

21 {
22 if(str.empty()) {
23 throw Invalid_Argument("Cannot register an empty name for an OID");
24 }
25
26 if(auto name = lookup_static_oid(oid)) {
27 if(*name != str) {
28 throw Invalid_State("Cannot register two different names to a single OID");
29 } else {
30 return;
31 }
32 }
33
34 const lock_guard_type<mutex_type> lock(m_mutex);
35
36 auto o2s = m_oid2str.find(oid);
37
38 if(o2s == m_oid2str.end()) {
39 m_oid2str.insert(std::make_pair(oid, str));
40 } else if(o2s->second != str) {
41 throw Invalid_State("Cannot register two different names to a single OID");
42 }
43
44 auto s2o = m_str2oid.find(std::string(str));
45
46 if(s2o == m_str2oid.end()) {
47 m_str2oid.insert(std::make_pair(str, oid));
48 }
49}
secure_vector< T > lock(const std::vector< T > &in)
Definition secmem.h:145
lock_guard< T > lock_guard_type
Definition mutex.h:58

References Botan::lock().

Referenced by Botan::OID::register_oid().

◆ add_oid2str()

void Botan::OID_Map::add_oid2str ( const OID & oid,
std::string_view str )

Definition at line 62 of file oid_map.cpp.

62 {
63 if(lookup_static_oid(oid).has_value()) {
64 return;
65 }
66
67 const lock_guard_type<mutex_type> lock(m_mutex);
68 if(!m_oid2str.contains(oid)) {
69 m_oid2str.insert(std::make_pair(oid, str));
70 }
71}

References Botan::lock().

Referenced by Botan::OIDS::add_oid2str().

◆ add_str2oid()

void Botan::OID_Map::add_str2oid ( const OID & oid,
std::string_view str )

Definition at line 51 of file oid_map.cpp.

51 {
52 if(lookup_static_oid_name(str).has_value()) {
53 return;
54 }
55
56 const lock_guard_type<mutex_type> lock(m_mutex);
57 if(!m_str2oid.contains(std::string(str))) {
58 m_str2oid.insert(std::make_pair(str, oid));
59 }
60}

References Botan::lock().

Referenced by Botan::OIDS::add_str2oid().

◆ global_registry()

OID_Map & Botan::OID_Map::global_registry ( )
static

Definition at line 16 of file oid_map.cpp.

16 {
17 static OID_Map g_map;
18 return g_map;
19}

Referenced by Botan::OIDS::add_oid2str(), Botan::OIDS::add_str2oid(), Botan::OID::from_name(), Botan::OID::from_string(), Botan::OID::register_oid(), and Botan::OID::registered_name().

◆ oid2str()

std::optional< std::string > Botan::OID_Map::oid2str ( const OID & oid)

Definition at line 73 of file oid_map.cpp.

73 {
74 if(auto name = lookup_static_oid(oid)) {
75 return std::string(*name);
76 }
77
78 const lock_guard_type<mutex_type> lock(m_mutex);
79
80 auto i = m_oid2str.find(oid);
81 if(i != m_oid2str.end()) {
82 return i->second;
83 }
84
85 return {};
86}

References Botan::lock().

Referenced by Botan::OID::registered_name().

◆ str2oid()

OID Botan::OID_Map::str2oid ( std::string_view str)

Definition at line 88 of file oid_map.cpp.

88 {
89 if(auto oid = lookup_static_oid_name(str)) {
90 return std::move(*oid);
91 }
92
93 const lock_guard_type<mutex_type> lock(m_mutex);
94 auto i = m_str2oid.find(std::string(str));
95 if(i != m_str2oid.end()) {
96 return i->second;
97 }
98
99 return OID();
100}

References Botan::lock().

Referenced by Botan::OID::from_name(), and Botan::OID::from_string().


The documentation for this class was generated from the following files: