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 #include <unordered_map>
13 
14 namespace Botan {
15 
16 namespace OIDS {
17 
18 /**
19 * Register an OID to string mapping.
20 * @param oid the oid to register
21 * @param name the name to be associated with the oid
22 */
23 BOTAN_UNSTABLE_API void add_oid(const OID& oid, const std::string& name);
24 
25 BOTAN_UNSTABLE_API void add_oid2str(const OID& oid, const std::string& name);
26 BOTAN_UNSTABLE_API void add_str2oid(const OID& oid, const std::string& name);
27 
28 BOTAN_UNSTABLE_API void add_oidstr(const char* oidstr, const char* name);
29 
30 std::unordered_map<std::string, std::string> load_oid2str_map();
31 std::unordered_map<std::string, OID> load_str2oid_map();
32 
33 /**
34 * Resolve an OID
35 * @param oid the OID to look up
36 * @return name associated with this OID, or an empty string
37 */
38 BOTAN_UNSTABLE_API std::string oid2str_or_empty(const OID& oid);
39 
40 /**
41 * Find the OID to a name. The lookup will be performed in the
42 * general OID section of the configuration.
43 * @param name the name to resolve
44 * @return OID associated with the specified name
45 */
46 BOTAN_UNSTABLE_API OID str2oid_or_empty(const std::string& name);
47 
48 BOTAN_UNSTABLE_API std::string oid2str_or_throw(const OID& oid);
49 
50 /**
51 * See if an OID exists in the internal table.
52 * @param oid the oid to check for
53 * @return true if the oid is registered
54 */
55 BOTAN_UNSTABLE_API bool BOTAN_DEPRECATED("Just lookup the value instead") have_oid(const std::string& oid);
56 
57 /**
58 * Tests whether the specified OID stands for the specified name.
59 * @param oid the OID to check
60 * @param name the name to check
61 * @return true if the specified OID stands for the specified name
62 */
name_of(const OID & oid,const std::string & name)63 inline bool BOTAN_DEPRECATED("Use oid == OID::from_string(name)") name_of(const OID& oid, const std::string& name)
64    {
65    return (oid == str2oid_or_empty(name));
66    }
67 
68 /**
69 * Prefer oid2str_or_empty
70 */
lookup(const OID & oid)71 inline std::string lookup(const OID& oid)
72    {
73    return oid2str_or_empty(oid);
74    }
75 
76 /**
77 * Prefer str2oid_or_empty
78 */
lookup(const std::string & name)79 inline OID lookup(const std::string& name)
80    {
81    return str2oid_or_empty(name);
82    }
83 
oid2str(const OID & oid)84 inline std::string BOTAN_DEPRECATED("Use oid2str_or_empty") oid2str(const OID& oid)
85    {
86    return oid2str_or_empty(oid);
87    }
88 
str2oid(const std::string & name)89 inline OID BOTAN_DEPRECATED("Use str2oid_or_empty") str2oid(const std::string& name)
90    {
91    return str2oid_or_empty(name);
92    }
93 
94 }
95 
96 }
97 
98 #endif
99