Botan: Botan::OID Class Reference

Botan 1.10.16

Public Member Functions | List of all members
Botan::OID Class Reference

`#include <asn1_oid.h>`

Inheritance diagram for Botan::OID:

## Public Member Functions
std::string | as_string () const
void | clear ()
void | decode_from (class BER_Decoder &)
void | encode_into (class DER_Encoder &) const
std::vector< u32bit > | get_id () const
bool | is_empty () const
| OID (const std::string &str="")
OID & | operator+= (u32bit new_comp)
bool | operator== (const OID &) const

## Detailed Description

This class represents ASN.1 object identifiers.

Definition at line 20 of file asn1_oid.h.

## Constructor & Destructor Documentation

## ◆ OID()

Botan::OID::OID | ( | const std::string & | str = `""` | ) |

Construct an OID from a string.

Parameters

  str | a string in the form "a.b.c" etc., where a,b,c are numbers

Definition at line 19 of file asn1_oid.cpp.

References Botan::parse_asn1_oid().

20 {
21 if(oid_str != "")
22 {
23 try
24 {
25 id = parse_asn1_oid(oid_str);
26 }
27 catch(...)
28 {
29 throw Invalid_OID(oid_str);
30 }
31
32 if(id.size() < 2 || id[0] > 2)
33 throw Invalid_OID(oid_str);
34 if((id[0] == 0 || id[0] == 1) && id[1] > 39)
35 throw Invalid_OID(oid_str);
36 }
37 }
Botan::parse_asn1_oid
std::vector< u32bit > parse_asn1_oid(const std::string &oid)
Definition: parsing.cpp:180

## Member Function Documentation

## ◆ as_string()

std::string Botan::OID::as_string | ( |  | ) | const

Get this OID as a string

Returns
  string representing this OID

Definition at line 50 of file asn1_oid.cpp.

References Botan::to_string().

Referenced by Botan::OIDS::add_oid(), Botan::CMS_Encoder::can_compress_with(), Botan::Extensions::decode_from(), Botan::EC_Group::EC_Group(), Botan::get_pbe(), Botan::X509_Object::hash_used_for_signature(), Botan::OIDS::lookup(), and Botan::make_public_key().

51 {
52 std::string oid_str;
53 for(size_t i = 0; i != id.size(); ++i)
54 {
55 oid_str += to_string(id[i]);
56 if(i != id.size() - 1)
57 oid_str += '.';
58 }
59 return oid_str;
60 }
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42

## ◆ clear()

void Botan::OID::clear | ( |  | ) |

Reset this instance to an empty OID.

Definition at line 42 of file asn1_oid.cpp.

Referenced by decode_from().

43 {
44 id.clear();
45 }

## ◆ decode_from()

void Botan::OID::decode_from | ( | class BER_Decoder & | from | ) |
| virtual

Decode whatever this object is from from

Parameters

  from | the BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 155 of file asn1_oid.cpp.

References Botan::BER_Object::class_tag, clear(), Botan::BER_Decoder::get_next_object(), Botan::OBJECT_ID, Botan::MemoryRegion< T >::size(), Botan::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.

156 {
157 BER_Object obj = decoder.get_next_object();
158 if(obj.type_tag != OBJECT_ID || obj.class_tag != UNIVERSAL)
159 throw BER_Bad_Tag("Error decoding OID, unknown tag",
160 obj.type_tag, obj.class_tag);
161 if(obj.value.size() < 2)
162 throw BER_Decoding_Error("OID encoding is too short");
163
164
165 clear();
166 id.push_back(obj.value[0] / 40);
167 id.push_back(obj.value[0] % 40);
168
169 size_t i = 0;
170 while(i != obj.value.size() - 1)
171 {
172 u32bit component = 0;
173 while(i != obj.value.size() - 1)
174 {
175 ++i;
176 component = (component << 7) + (obj.value[i] & 0x7F);
177 if(!(obj.value[i] & 0x80))
178 break;
179 }
180 id.push_back(component);
181 }
182 }
Botan::OBJECT_ID
Definition: asn1_int.h:33
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::OID::clear
void clear()
Definition: asn1_oid.cpp:42
Botan::u32bit
unsigned int u32bit
Definition: types.h:32

## ◆ encode_into()

void Botan::OID::encode_into | ( | class DER_Encoder & | to | ) | const
| virtual

Encode whatever this object is into to

Parameters

  to | the DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 127 of file asn1_oid.cpp.

References Botan::DER_Encoder::add_object(), Botan::high_bit(), Botan::OBJECT_ID, Botan::MemoryRegion< T >::push_back(), and Botan::UNIVERSAL.

128 {
129 if(id.size() < 2)
130 throw Invalid_Argument("OID::encode_into: OID is invalid");
131
132 MemoryVector<byte> encoding;
133 encoding.push_back(40 * id[0] + id[1]);
134
135 for(size_t i = 2; i != id.size(); ++i)
136 {
137 if(id[i] == 0)
138 encoding.push_back(0);
139 else
140 {
141 size_t blocks = high_bit(id[i]) + 6;
142 blocks = (blocks - (blocks % 7)) / 7;
143
144 for(size_t j = 0; j != blocks - 1; ++j)
145 encoding.push_back(0x80 | ((id[i] >> 7*(blocks-j-1)) & 0x7F));
146 encoding.push_back(id[i] & 0x7F);
147 }
148 }
149 der.add_object(OBJECT_ID, UNIVERSAL, encoding);
150 }
Botan::OBJECT_ID
Definition: asn1_int.h:33
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::UNIVERSAL
Definition: asn1_int.h:20
Botan::high_bit
size_t high_bit(T n)
Definition: bit_ops.h:33

## ◆ get_id()

std::vector<u32bit> Botan::OID::get_id | ( |  | ) | const
| inline

Get this OID as list (vector) of its components.

Returns
  vector representing this OID

Definition at line 36 of file asn1_oid.h.

References oid, Botan::operator!=(), Botan::operator+(), Botan::operator+=(), Botan::operator<(), and Botan::operator==().

Referenced by Botan::operator<().

36 { return id; }

## ◆ is_empty()

bool Botan::OID::is_empty | ( |  | ) | const
| inline

Find out whether this OID is empty

Returns
  true is no OID value is set

Definition at line 30 of file asn1_oid.h.

30 { return id.size() == 0; }

## ◆ operator+=()

OID & Botan::OID::operator+= | ( | u32bit | new_comp | ) |

Add a component to this OID.

Parameters

  new_comp | the new component to add to the end of this OID

Returns
  reference to *this

Definition at line 78 of file asn1_oid.cpp.

79 {
80 id.push_back(component);
81 return (*this);
82 }

## ◆ operator==()

bool Botan::OID::operator== | ( | const OID & | oid | ) | const

Compare two OIDs.

Returns
  true if they are equal, false otherwise

Definition at line 65 of file asn1_oid.cpp.

66 {
67 if(id.size() != oid.id.size())
68 return false;
69 for(size_t i = 0; i != id.size(); ++i)
70 if(id[i] != oid.id[i])
71 return false;
72 return true;
73 }
oid
OID oid
Definition: x509_ext.cpp:446

The documentation for this class was generated from the following files:

- src/asn1/asn1_oid.h
- src/asn1/asn1_oid.cpp