Botan
1.11.15
|
#include <asn1_oid.h>
Public Member Functions | |
std::string | as_string () const |
void | clear () |
void | decode_from (class BER_Decoder &) |
bool | empty () const |
void | encode_into (class DER_Encoder &) const |
const std::vector< u32bit > & | get_id () const |
OID (const std::string &str="") | |
OID & | operator+= (u32bit new_comp) |
bool | operator== (const OID &) const |
This class represents ASN.1 object identifiers.
Definition at line 20 of file asn1_oid.h.
Botan::OID::OID | ( | const std::string & | str = "" | ) |
Construct an OID from a string.
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().
{ if(oid_str != "") { try { id = parse_asn1_oid(oid_str); } catch(...) { throw Invalid_OID(oid_str); } if(id.size() < 2 || id[0] > 2) throw Invalid_OID(oid_str); if((id[0] == 0 || id[0] == 1) && id[1] > 39) throw Invalid_OID(oid_str); } }
std::string Botan::OID::as_string | ( | ) | const |
Get this OID as a string
Definition at line 50 of file asn1_oid.cpp.
References Botan::ASN1::to_string().
Referenced by Botan::Extensions::decode_from(), Botan::EC_Group::EC_Group(), Botan::X509_Object::hash_used_for_signature(), Botan::PKCS8::load_key(), Botan::make_private_key(), Botan::make_public_key(), and Botan::pbes2_decrypt().
{ std::string oid_str; for(size_t i = 0; i != id.size(); ++i) { oid_str += std::to_string(id[i]); if(i != id.size() - 1) oid_str += '.'; } return oid_str; }
void Botan::OID::clear | ( | ) |
Reset this instance to an empty OID.
Definition at line 42 of file asn1_oid.cpp.
Referenced by decode_from().
{
id.clear();
}
void Botan::OID::decode_from | ( | class BER_Decoder & | from | ) | [virtual] |
Decode whatever this object is from from
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::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.
{ BER_Object obj = decoder.get_next_object(); if(obj.type_tag != OBJECT_ID || obj.class_tag != UNIVERSAL) throw BER_Bad_Tag("Error decoding OID, unknown tag", obj.type_tag, obj.class_tag); if(obj.value.size() < 2) throw BER_Decoding_Error("OID encoding is too short"); clear(); id.push_back(obj.value[0] / 40); id.push_back(obj.value[0] % 40); size_t i = 0; while(i != obj.value.size() - 1) { u32bit component = 0; while(i != obj.value.size() - 1) { ++i; if(component >> (32-7)) throw Decoding_Error("OID component overflow"); component = (component << 7) + (obj.value[i] & 0x7F); if(!(obj.value[i] & 0x80)) break; } id.push_back(component); } }
bool Botan::OID::empty | ( | ) | const [inline] |
Find out whether this OID is empty
Definition at line 30 of file asn1_oid.h.
Referenced by Botan::EC_PrivateKey::EC_PrivateKey().
{ return id.size() == 0; }
void Botan::OID::encode_into | ( | class DER_Encoder & | to | ) | const [virtual] |
Encode whatever this object is into to
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, and Botan::UNIVERSAL.
{ if(id.size() < 2) throw Invalid_Argument("OID::encode_into: OID is invalid"); std::vector<byte> encoding; encoding.push_back(40 * id[0] + id[1]); for(size_t i = 2; i != id.size(); ++i) { if(id[i] == 0) encoding.push_back(0); else { size_t blocks = high_bit(id[i]) + 6; blocks = (blocks - (blocks % 7)) / 7; for(size_t j = 0; j != blocks - 1; ++j) encoding.push_back(0x80 | ((id[i] >> 7*(blocks-j-1)) & 0x7F)); encoding.push_back(id[i] & 0x7F); } } der.add_object(OBJECT_ID, UNIVERSAL, encoding); }
const std::vector<u32bit>& Botan::OID::get_id | ( | ) | const [inline] |
Get this OID as list (vector) of its components.
Definition at line 36 of file asn1_oid.h.
Referenced by Botan::operator<().
{ return id; }
Add a component to this OID.
new_comp | the new component to add to the end of this OID |
Definition at line 78 of file asn1_oid.cpp.
{ id.push_back(component); return (*this); }
bool Botan::OID::operator== | ( | const OID & | oid | ) | const |
Compare two OIDs.
Definition at line 65 of file asn1_oid.cpp.
{ if(id.size() != oid.id.size()) return false; for(size_t i = 0; i != id.size(); ++i) if(id[i] != oid.id[i]) return false; return true; }