Botan  2.7.0
Crypto and TLS for C++11
asn1_oid.h
Go to the documentation of this file.
1 /*
2 * ASN.1 OID
3 * (C) 1999-2007 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  void encode_into(class DER_Encoder&) const override;
24  void decode_from(class BER_Decoder&) override;
25 
26  /**
27  * Find out whether this OID is empty
28  * @return true is no OID value is set
29  */
30  bool empty() const { return m_id.empty(); }
31 
32  /**
33  * Find out whether this OID has a value
34  * @return true is this OID has a value
35  */
36  bool has_value() const { return (m_id.empty() == false); }
37 
38  /**
39  * Get this OID as list (vector) of its components.
40  * @return vector representing this OID
41  */
42  const std::vector<uint32_t>& get_id() const { return m_id; }
43 
44  /**
45  * Get this OID as a string
46  * @return string representing this OID
47  */
48  std::string as_string() const { return this->to_string(); }
49 
50  /**
51  * Get this OID as a string
52  * @return string representing this OID
53  */
54  std::string to_string() const;
55 
56  /**
57  * Compare two OIDs.
58  * @return true if they are equal, false otherwise
59  */
60  bool operator==(const OID&) const;
61 
62  /**
63  * Reset this instance to an empty OID.
64  */
65  void clear();
66 
67  /**
68  * Add a component to this OID.
69  * @param new_comp the new component to add to the end of this OID
70  * @return reference to *this
71  */
72  OID& operator+=(uint32_t new_comp);
73 
74  /**
75  * Construct an OID from a string.
76  * @param str a string in the form "a.b.c" etc., where a,b,c are numbers
77  */
78  OID(const std::string& str = "");
79 
80  explicit OID(std::initializer_list<uint32_t> init) : m_id(init) {}
81  private:
82  std::vector<uint32_t> m_id;
83  };
84 
85 /**
86 * Append another component onto the OID.
87 * @param oid the OID to add the new component to
88 * @param new_comp the new component to add
89 */
90 OID BOTAN_PUBLIC_API(2,0) operator+(const OID& oid, uint32_t new_comp);
91 
92 /**
93 * Compare two OIDs.
94 * @param a the first OID
95 * @param b the second OID
96 * @return true if a is not equal to b
97 */
98 bool BOTAN_PUBLIC_API(2,0) operator!=(const OID& a, const OID& b);
99 
100 /**
101 * Compare two OIDs.
102 * @param a the first OID
103 * @param b the second OID
104 * @return true if a is lexicographically smaller than b
105 */
106 bool BOTAN_PUBLIC_API(2,0) operator<(const OID& a, const OID& b);
107 
108 }
109 
110 #endif
OID(std::initializer_list< uint32_t > init)
Definition: asn1_oid.h:80
std::string as_string() const
Definition: asn1_oid.h:48
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool empty() const
Definition: asn1_oid.h:30
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
Definition: secmem.h:133
Definition: alg_id.cpp:13
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition: stl_util.h:25
bool has_value() const
Definition: asn1_oid.h:36
const std::vector< uint32_t > & get_id() const
Definition: asn1_oid.h:42
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:75