Botan::OID Class Reference

#include <asn1_oid.h>

Inheritance diagram for Botan::OID:

Botan::ASN1_Object

List of all members.

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< u32bitget_id () const
bool is_empty () const
 OID (const std::string &str="")
OIDoperator+= (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

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().

00020    {
00021    if(oid_str != "")
00022       {
00023       try
00024          {
00025          id = parse_asn1_oid(oid_str);
00026          }
00027       catch(...)
00028          {
00029          throw Invalid_OID(oid_str);
00030          }
00031 
00032       if(id.size() < 2 || id[0] > 2)
00033          throw Invalid_OID(oid_str);
00034       if((id[0] == 0 || id[0] == 1) && id[1] > 39)
00035          throw Invalid_OID(oid_str);
00036       }
00037    }


Member Function Documentation

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::Extensions::decode_from(), Botan::EC_Domain_Params::EC_Domain_Params(), Botan::get_pbe(), Botan::PKCS8::load_key(), Botan::OIDS::lookup(), Botan::make_private_key(), Botan::make_public_key(), and Botan::X942_PRF::X942_PRF().

00051    {
00052    std::string oid_str;
00053    for(u32bit j = 0; j != id.size(); ++j)
00054       {
00055       oid_str += to_string(id[j]);
00056       if(j != id.size() - 1)
00057          oid_str += '.';
00058       }
00059    return oid_str;
00060    }

void Botan::OID::clear (  ) 

Reset this instance to an empty OID.

Definition at line 42 of file asn1_oid.cpp.

Referenced by decode_from().

00043    {
00044    id.clear();
00045    }

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.

00156    {
00157    BER_Object obj = decoder.get_next_object();
00158    if(obj.type_tag != OBJECT_ID || obj.class_tag != UNIVERSAL)
00159       throw BER_Bad_Tag("Error decoding OID, unknown tag",
00160                         obj.type_tag, obj.class_tag);
00161    if(obj.value.size() < 2)
00162       throw BER_Decoding_Error("OID encoding is too short");
00163 
00164 
00165    clear();
00166    id.push_back(obj.value[0] / 40);
00167    id.push_back(obj.value[0] % 40);
00168 
00169    u32bit j = 0;
00170    while(j != obj.value.size() - 1)
00171       {
00172       u32bit component = 0;
00173       while(j != obj.value.size() - 1)
00174          {
00175          ++j;
00176          component = (component << 7) + (obj.value[j] & 0x7F);
00177          if(!(obj.value[j] & 0x80))
00178             break;
00179          }
00180       id.push_back(component);
00181       }
00182    }

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::MemoryRegion< T >::append(), Botan::high_bit(), Botan::OBJECT_ID, and Botan::UNIVERSAL.

00128    {
00129    if(id.size() < 2)
00130       throw Invalid_Argument("OID::encode_into: OID is invalid");
00131 
00132    MemoryVector<byte> encoding;
00133    encoding.append(40 * id[0] + id[1]);
00134 
00135    for(u32bit j = 2; j != id.size(); ++j)
00136       {
00137       if(id[j] == 0)
00138          encoding.append(0);
00139       else
00140          {
00141          u32bit blocks = high_bit(id[j]) + 6;
00142          blocks = (blocks - (blocks % 7)) / 7;
00143 
00144          for(u32bit k = 0; k != blocks - 1; ++k)
00145             encoding.append(0x80 | ((id[j] >> 7*(blocks-k-1)) & 0x7F));
00146          encoding.append(id[j] & 0x7F);
00147          }
00148       }
00149    der.add_object(OBJECT_ID, UNIVERSAL, encoding);
00150    }

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.

Referenced by Botan::operator<().

00036 { return id; }

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.

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

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.

00079    {
00080    id.push_back(component);
00081    return (*this);
00082    }

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.

References id.

00066    {
00067    if(id.size() != oid.id.size())
00068       return false;
00069    for(u32bit j = 0; j != id.size(); ++j)
00070       if(id[j] != oid.id[j])
00071          return false;
00072    return true;
00073    }


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

Generated on Fri Aug 13 16:20:59 2010 for Botan by  doxygen 1.5.8