Coverage Report

Created: 2020-06-30 13:58

/src/botan/build/include/botan/asn1_oid.h
Line
Count
Source (jump to first uncovered line)
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
259k
      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
23.4k
      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
0
      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
21.3k
      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
37.0k
      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
1.39M
      const std::vector<uint32_t>& get_components() const { return m_id; }
72
73
0
      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
0
         {
81
0
         return this->to_string();
82
0
         }
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
583k
         {
102
583k
         return m_id == other.m_id;
103
583k
         }
104
105
      /**
106
      * Reset this instance to an empty OID.
107
      */
108
0
      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
0
         {
117
0
         m_id.push_back(new_comp);
118
0
         return (*this);
119
0
         }
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
86.0k
   {
140
86.0k
   return !(a == b);
141
86.0k
   }
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