Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

asn1_oid.h
Go to the documentation of this file.
1 /*
2 * ASN.1 OID
3 * (C) 1999-2007,2019 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_ASN1_OID_H_
9 #define BOTAN_ASN1_OID_H_
10
11 #include <botan/asn1_obj.h>
12 #include <string>
13 #include <vector>
14
15 namespace Botan {
16
17 /**
18 * This class represents ASN.1 object identifiers.
19 */
20 class BOTAN_PUBLIC_API(2,0) OID final : public ASN1_Object
21 {
22 public:
23
24 /**
25 * Create an uninitialied OID object
26 */
27 explicit OID() {}
28
29 /**
30 * Construct an OID from a string.
31 * @param str a string in the form "a.b.c" etc., where a,b,c are numbers
32 */
33 explicit OID(const std::string& str);
34
35 /**
36 * Initialize an OID from a sequence of integer values
37 */
38 explicit OID(std::initializer_list<uint32_t> init) : m_id(init) {}
39
40 /**
41 * Initialize an OID from a vector of integer values
42 */
43 explicit OID(std::vector<uint32_t>&& init) : m_id(init) {}
44
45 /**
46 * Construct an OID from a string.
47 * @param str a string in the form "a.b.c" etc., where a,b,c are numbers
48 * or any known OID name (for example "RSA" or "X509v3.SubjectKeyIdentifier")
49 */
50 static OID from_string(const std::string& str);
51
52 void encode_into(class DER_Encoder&) const override;
53 void decode_from(class BER_Decoder&) override;
54
55 /**
56 * Find out whether this OID is empty
57 * @return true is no OID value is set
58 */
59 bool empty() const { return m_id.empty(); }
60
61 /**
62 * Find out whether this OID has a value
63 * @return true is this OID has a value
64 */
65 bool has_value() const { return (m_id.empty() == false); }
66
67 /**
68 * Get this OID as list (vector) of its components.
69 * @return vector representing this OID
70 */
71 const std::vector<uint32_t>& get_components() const { return m_id; }
72
73 const std::vector<uint32_t>& get_id() const { return get_components(); }
74
75 /**
76 * Get this OID as a string
77 * @return string representing this OID
78 */
79 std::string BOTAN_DEPRECATED("Use OID::to_string") as_string() const
80 {
81 return this->to_string();
82 }
83
84 /**
85 * Get this OID as a dotted-decimal string
86 * @return string representing this OID
87 */
88 std::string to_string() const;
89
90 /**
91 * If there is a known name associated with this OID, return that.
92 * Otherwise return the result of to_string
93 */
94 std::string to_formatted_string() const;
95
96 /**
97 * Compare two OIDs.
98 * @return true if they are equal, false otherwise
99 */
100 bool operator==(const OID& other) const
101 {
102 return m_id == other.m_id;
103 }
104
105 /**
106 * Reset this instance to an empty OID.
107 */
108 void BOTAN_DEPRECATED("Avoid mutation of OIDs") clear() { m_id.clear(); }
109
110 /**
111 * Add a component to this OID.
112 * @param new_comp the new component to add to the end of this OID
113 * @return reference to *this
114 */
115 BOTAN_DEPRECATED("Avoid mutation of OIDs") OID& operator+=(uint32_t new_comp)
116 {
117 m_id.push_back(new_comp);
118 return (*this);
119 }
120
121 private:
122 std::vector<uint32_t> m_id;
123 };
124
125 /**
126 * Append another component onto the OID.
127 * @param oid the OID to add the new component to
128 * @param new_comp the new component to add
129 */
130 OID BOTAN_PUBLIC_API(2,0) operator+(const OID& oid, uint32_t new_comp);
131
132 /**
133 * Compare two OIDs.
134 * @param a the first OID
135 * @param b the second OID
136 * @return true if a is not equal to b
137 */
138 inline bool operator!=(const OID& a, const OID& b)
139 {
140 return !(a == b);
141 }
142
143 /**
144 * Compare two OIDs.
145 * @param a the first OID
146 * @param b the second OID
147 * @return true if a is lexicographically smaller than b
148 */
149 bool BOTAN_PUBLIC_API(2,0) operator<(const OID& a, const OID& b);
150
151 }
152
153 #endif
Botan::OID::get_components
const std::vector< uint32_t > & get_components() const
Definition: asn1_oid.h:71
Botan::ASN1_Object
Definition: asn1_obj.h:66
Botan::OID::OID
OID(std::initializer_list< uint32_t > init)
Definition: asn1_oid.h:38
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
Botan::OID::OID
OID()
Definition: asn1_oid.h:27
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::OID::operator==
bool operator==(const OID &other) const
Definition: asn1_oid.h:100
Botan::to_string
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition: exceptn.cpp:11
Botan::DER_Encoder
Definition: der_enc.h:23
Botan
Definition: alg_id.cpp:13
Botan::OID::has_value
bool has_value() const
Definition: asn1_oid.h:65
Botan::OID::empty
bool empty() const
Definition: asn1_oid.h:59
init
int(* init)(CTX *)
Definition: commoncrypto_hash.cpp:26
Botan::OID::get_id
const std::vector< uint32_t > & get_id() const
Definition: asn1_oid.h:73
Botan::OID
Definition: asn1_oid.h:20
Botan::OID::OID
OID(std::vector< uint32_t > &&init)
Definition: asn1_oid.h:43
Botan::BER_Decoder
Definition: ber_dec.h:21