Botan  2.4.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.size() == 0; }
31 
32  /**
33  * Get this OID as list (vector) of its components.
34  * @return vector representing this OID
35  */
36  const std::vector<uint32_t>& get_id() const { return m_id; }
37 
38  /**
39  * Get this OID as a string
40  * @return string representing this OID
41  */
42  std::string as_string() const;
43 
44  /**
45  * Compare two OIDs.
46  * @return true if they are equal, false otherwise
47  */
48  bool operator==(const OID&) const;
49 
50  /**
51  * Reset this instance to an empty OID.
52  */
53  void clear();
54 
55  /**
56  * Add a component to this OID.
57  * @param new_comp the new component to add to the end of this OID
58  * @return reference to *this
59  */
60  OID& operator+=(uint32_t new_comp);
61 
62  /**
63  * Construct an OID from a string.
64  * @param str a string in the form "a.b.c" etc., where a,b,c are numbers
65  */
66  OID(const std::string& str = "");
67  private:
68  std::vector<uint32_t> m_id;
69  };
70 
71 /**
72 * Append another component onto the OID.
73 * @param oid the OID to add the new component to
74 * @param new_comp the new component to add
75 */
76 OID BOTAN_PUBLIC_API(2,0) operator+(const OID& oid, uint32_t new_comp);
77 
78 /**
79 * Compare two OIDs.
80 * @param a the first OID
81 * @param b the second OID
82 * @return true if a is not equal to b
83 */
84 bool BOTAN_PUBLIC_API(2,0) operator!=(const OID& a, const OID& b);
85 
86 /**
87 * Compare two OIDs.
88 * @param a the first OID
89 * @param b the second OID
90 * @return true if a is lexicographically smaller than b
91 */
92 bool BOTAN_PUBLIC_API(2,0) operator<(const OID& a, const OID& b);
93 
94 }
95 
96 #endif
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:90
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool operator<(const OID &a, const OID &b)
Definition: asn1_oid.cpp:105
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:131
Definition: alg_id.cpp:13
OID operator+(const OID &oid, uint32_t component)
Definition: asn1_oid.cpp:87
const std::vector< uint32_t > & get_id() const
Definition: asn1_oid.h:36
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:75