Botan 3.13.0
Crypto and TLS for C&
oids.h
Go to the documentation of this file.
1/*
2* OID Registry
3* (C) 1999-2007 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_OIDS_H_
9#define BOTAN_OIDS_H_
10
11#include <botan/asn1_obj.h>
12
14
15namespace Botan::OIDS {
16
17/**
18* Register an OID to string mapping.
19* @param oid the oid to register
20* @param name the name to be associated with the oid
21*/
22BOTAN_DEPRECATED("Use OID::register_oid") inline void add_oid(const OID& oid, std::string_view name) {
23 OID::register_oid(oid, name);
24}
25
26/**
27* Register an OID to string mapping.
28* @param oid the oid to register
29* @param name the name to be associated with the oid
30*/
31BOTAN_DEPRECATED("Use OID::register_oid") BOTAN_UNSTABLE_API void add_oid2str(const OID& oid, std::string_view name);
32
33/**
34* Register a string to OID mapping.
35* @param oid the oid to register
36* @param name the name to be associated with the oid
37*/
38BOTAN_DEPRECATED("Use OID::register_oid") BOTAN_UNSTABLE_API void add_str2oid(const OID& oid, std::string_view name);
39
40/**
41* Register an OID to string mapping.
42* @param oidstr the oid to register, as a dotted decimal string
43* @param name the name to be associated with the oid
44*/
45BOTAN_DEPRECATED("Use OID::register_oid") inline void add_oidstr(const char* oidstr, const char* name) {
46 OID::register_oid(OID(oidstr), name);
47}
48
49/**
50* Resolve an OID
51* @param oid the OID to look up
52* @return name associated with this OID, or an empty string
53*/
54BOTAN_DEPRECATED("Use OID::registered_name") inline std::string oid2str_or_empty(const OID& oid) {
55 return oid.registered_name().value_or("");
56}
57
58/**
59* Find the OID to a name. The lookup will be performed in the
60* general OID section of the configuration.
61* @param name the name to resolve
62* @return OID associated with the specified name
63*/
64BOTAN_DEPRECATED("Use OID::from_name") inline OID str2oid_or_empty(std::string_view name) {
65 return OID::from_name(name).value_or(OID());
66}
67
68/**
69* Resolve an OID
70* @param oid the OID to look up
71* @return name associated with this OID
72* @throws Lookup_Error if the OID is not registered
73*/
74BOTAN_DEPRECATED("Use OID::registered_name") inline std::string oid2str_or_throw(const OID& oid) {
75 if(const auto name = oid.registered_name()) {
76 return *name;
77 } else {
78 throw Lookup_Error("No name associated with OID " + oid.to_string());
79 }
80}
81
82/**
83* Resolve an OID
84* @param oid the OID to look up
85* @return name associated with this OID, or an empty string
86*/
87BOTAN_DEPRECATED("Use OID::registered_name") inline std::string lookup(const OID& oid) {
88 return oid.human_name_or_empty();
89}
90
91/**
92* Find the OID associated with a name
93* @param name the name to resolve
94* @return OID associated with the specified name, or an empty OID
95*/
96BOTAN_DEPRECATED("Use OID::from_name") inline OID lookup(std::string_view name) {
97 return OID::from_name(name).value_or(OID());
98}
99
100} // namespace Botan::OIDS
101
102#endif
#define BOTAN_DEPRECATED_HEADER(hdr)
Definition api.h:100
#define BOTAN_UNSTABLE_API
Definition api.h:34
#define BOTAN_DEPRECATED(msg)
Definition api.h:73
static std::optional< OID > from_name(std::string_view name)
Definition asn1_oid.cpp:66
static void register_oid(const OID &oid, std::string_view name)
Definition asn1_oid.cpp:61
std::string oid2str_or_throw(const OID &oid)
Definition oids.h:74
void add_oidstr(const char *oidstr, const char *name)
Definition oids.h:45
std::string oid2str_or_empty(const OID &oid)
Definition oids.h:54
std::string lookup(const OID &oid)
Definition oids.h:87
void add_oid(const OID &oid, std::string_view name)
Definition oids.h:22
OID str2oid_or_empty(std::string_view name)
Definition oids.h:64