Botan::DER_Encoder Class Reference

#include <der_enc.h>

List of all members.

Classes

class  DER_Sequence

Public Member Functions

DER_Encoderadd_object (ASN1_Tag, ASN1_Tag, byte)
DER_Encoderadd_object (ASN1_Tag, ASN1_Tag, const std::string &)
DER_Encoderadd_object (ASN1_Tag, ASN1_Tag, const MemoryRegion< byte > &)
DER_Encoderadd_object (ASN1_Tag, ASN1_Tag, const byte[], u32bit)
DER_Encoderencode (const ASN1_Object &)
DER_Encoderencode (const byte[], u32bit, ASN1_Tag, ASN1_Tag, ASN1_Tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const MemoryRegion< byte > &, ASN1_Tag, ASN1_Tag, ASN1_Tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const BigInt &, ASN1_Tag, ASN1_Tag=CONTEXT_SPECIFIC)
DER_Encoderencode (u32bit, ASN1_Tag, ASN1_Tag=CONTEXT_SPECIFIC)
DER_Encoderencode (bool, ASN1_Tag, ASN1_Tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const byte[], u32bit, ASN1_Tag)
DER_Encoderencode (const MemoryRegion< byte > &, ASN1_Tag)
DER_Encoderencode (const BigInt &)
DER_Encoderencode (u32bit)
DER_Encoderencode (bool)
DER_Encoderencode_if (bool, DER_Encoder &)
template<typename T >
DER_Encoderencode_list (const std::vector< T > &values)
DER_Encoderencode_null ()
template<typename T >
DER_Encoderencode_optional (const T &value, const T &default_value)
DER_Encoderend_cons ()
DER_Encoderend_explicit ()
SecureVector< byteget_contents ()
DER_Encoderraw_bytes (const MemoryRegion< byte > &)
DER_Encoderraw_bytes (const byte[], u32bit)
DER_Encoderstart_cons (ASN1_Tag, ASN1_Tag=UNIVERSAL)
DER_Encoderstart_explicit (u16bit)


Detailed Description

General DER Encoding Object

Definition at line 22 of file der_enc.h.


Member Function Documentation

DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
byte  rep 
)

Definition at line 387 of file der_enc.cpp.

References add_object().

00389    {
00390    return add_object(type_tag, class_tag, &rep, 1);
00391    }

DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const std::string &  rep_str 
)

Definition at line 376 of file der_enc.cpp.

References add_object().

00378    {
00379    const byte* rep = reinterpret_cast<const byte*>(rep_str.data());
00380    const u32bit rep_len = rep_str.size();
00381    return add_object(type_tag, class_tag, rep, rep_len);
00382    }

DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const MemoryRegion< byte > &  rep_buf 
)

Definition at line 365 of file der_enc.cpp.

References add_object(), Botan::MemoryRegion< T >::begin(), and Botan::MemoryRegion< T >::size().

00367    {
00368    const byte* rep = rep_buf.begin();
00369    const u32bit rep_len = rep_buf.size();
00370    return add_object(type_tag, class_tag, rep, rep_len);
00371    }

DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const byte  rep[],
u32bit  length 
)

Definition at line 348 of file der_enc.cpp.

References Botan::MemoryRegion< T >::append(), and raw_bytes().

Referenced by add_object(), encode(), Botan::EAC_Time::encode_into(), Botan::ASN1_EAC_String::encode_into(), Botan::X509_Time::encode_into(), Botan::ASN1_String::encode_into(), Botan::OID::encode_into(), and encode_null().

00350    {
00351    SecureVector<byte> encoded_tag = encode_tag(type_tag, class_tag);
00352    SecureVector<byte> encoded_length = encode_length(length);
00353 
00354    SecureVector<byte> buffer;
00355    buffer.append(encoded_tag);
00356    buffer.append(encoded_length);
00357    buffer.append(rep, length);
00358 
00359    return raw_bytes(buffer);
00360    }

DER_Encoder & Botan::DER_Encoder::encode ( const ASN1_Object obj  ) 

Definition at line 339 of file der_enc.cpp.

References Botan::ASN1_Object::encode_into().

00340    {
00341    obj.encode_into(*this);
00342    return (*this);
00343    }

DER_Encoder & Botan::DER_Encoder::encode ( const byte  bytes[],
u32bit  length,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 308 of file der_enc.cpp.

References add_object(), Botan::MemoryRegion< T >::append(), Botan::BIT_STRING, and Botan::OCTET_STRING.

00311    {
00312    if(real_type != OCTET_STRING && real_type != BIT_STRING)
00313       throw Invalid_Argument("DER_Encoder: Invalid tag for byte/bit string");
00314 
00315    if(real_type == BIT_STRING)
00316       {
00317       SecureVector<byte> encoded;
00318       encoded.append(0);
00319       encoded.append(bytes, length);
00320       return add_object(type_tag, class_tag, encoded);
00321       }
00322    else
00323       return add_object(type_tag, class_tag, bytes, length);
00324    }

DER_Encoder & Botan::DER_Encoder::encode ( const MemoryRegion< byte > &  bytes,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 297 of file der_enc.cpp.

References Botan::MemoryRegion< T >::begin(), encode(), and Botan::MemoryRegion< T >::size().

00300    {
00301    return encode(bytes.begin(), bytes.size(),
00302                  real_type, type_tag, class_tag);
00303    }

DER_Encoder & Botan::DER_Encoder::encode ( const BigInt n,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 273 of file der_enc.cpp.

References add_object(), Botan::MemoryRegion< T >::begin(), Botan::BigInt::bits(), Botan::BigInt::bytes(), encode(), and Botan::MemoryRegion< T >::size().

00275    {
00276    if(n == 0)
00277       return add_object(type_tag, class_tag, 0);
00278 
00279    bool extra_zero = (n.bits() % 8 == 0);
00280    SecureVector<byte> contents(extra_zero + n.bytes());
00281    BigInt::encode(contents.begin() + extra_zero, n);
00282    if(n < 0)
00283       {
00284       for(u32bit j = 0; j != contents.size(); ++j)
00285          contents[j] = ~contents[j];
00286       for(u32bit j = contents.size(); j > 0; --j)
00287          if(++contents[j-1])
00288             break;
00289       }
00290 
00291    return add_object(type_tag, class_tag, contents);
00292    }

DER_Encoder & Botan::DER_Encoder::encode ( u32bit  n,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 264 of file der_enc.cpp.

References encode().

00266    {
00267    return encode(BigInt(n), type_tag, class_tag);
00268    }

DER_Encoder & Botan::DER_Encoder::encode ( bool  is_true,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 254 of file der_enc.cpp.

References add_object().

00256    {
00257    byte val = is_true ? 0xFF : 0x00;
00258    return add_object(type_tag, class_tag, &val, 1);
00259    }

DER_Encoder & Botan::DER_Encoder::encode ( const byte  bytes[],
u32bit  length,
ASN1_Tag  real_type 
)

Definition at line 245 of file der_enc.cpp.

References encode(), and Botan::UNIVERSAL.

00247    {
00248    return encode(bytes, length, real_type, real_type, UNIVERSAL);
00249    }

DER_Encoder & Botan::DER_Encoder::encode ( const MemoryRegion< byte > &  bytes,
ASN1_Tag  real_type 
)

Definition at line 235 of file der_enc.cpp.

References Botan::MemoryRegion< T >::begin(), encode(), Botan::MemoryRegion< T >::size(), and Botan::UNIVERSAL.

00237    {
00238    return encode(bytes.begin(), bytes.size(),
00239                  real_type, real_type, UNIVERSAL);
00240    }

DER_Encoder & Botan::DER_Encoder::encode ( const BigInt n  ) 

Definition at line 227 of file der_enc.cpp.

References encode(), Botan::INTEGER, and Botan::UNIVERSAL.

00228    {
00229    return encode(n, INTEGER, UNIVERSAL);
00230    }

DER_Encoder & Botan::DER_Encoder::encode ( u32bit  n  ) 

Definition at line 219 of file der_enc.cpp.

References encode(), Botan::INTEGER, and Botan::UNIVERSAL.

00220    {
00221    return encode(BigInt(n), INTEGER, UNIVERSAL);
00222    }

DER_Encoder & Botan::DER_Encoder::encode ( bool  is_true  ) 

DER_Encoder & Botan::DER_Encoder::encode_if ( bool  cond,
DER_Encoder codec 
)

Definition at line 329 of file der_enc.cpp.

References get_contents(), and raw_bytes().

00330    {
00331    if(cond)
00332       return raw_bytes(codec.get_contents());
00333    return (*this);
00334    }

template<typename T >
DER_Encoder& Botan::DER_Encoder::encode_list ( const std::vector< T > &  values  )  [inline]

Definition at line 61 of file der_enc.h.

References Botan::X509::encode().

00062          {
00063          for(u32bit j = 0; j != values.size(); ++j)
00064             encode(values[j]);
00065          return (*this);
00066          }

DER_Encoder & Botan::DER_Encoder::encode_null (  ) 

Definition at line 203 of file der_enc.cpp.

References add_object(), Botan::NULL_TAG, and Botan::UNIVERSAL.

00204    {
00205    return add_object(NULL_TAG, UNIVERSAL, 0, 0);
00206    }

template<typename T >
DER_Encoder& Botan::DER_Encoder::encode_optional ( const T &  value,
const T &  default_value 
) [inline]

Definition at line 53 of file der_enc.h.

References Botan::X509::encode().

00054          {
00055          if(value != default_value)
00056             encode(value);
00057          return (*this);
00058          }

DER_Encoder & Botan::DER_Encoder::end_cons (  ) 

Definition at line 147 of file der_enc.cpp.

References raw_bytes().

Referenced by Botan::X509::create_cert_req(), Botan::CMS_Encoder::digest(), Botan::CRL_Entry::encode_into(), Botan::X509_DN::encode_into(), Botan::Attribute::encode_into(), Botan::AlternativeName::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::CMS_Encoder::encrypt(), end_explicit(), and Botan::CMS_Encoder::sign().

00148    {
00149    if(subsequences.empty())
00150       throw Invalid_State("DER_Encoder::end_cons: No such sequence");
00151 
00152    SecureVector<byte> seq = subsequences[subsequences.size()-1].get_contents();
00153    subsequences.pop_back();
00154    raw_bytes(seq);
00155    return (*this);
00156    }

DER_Encoder & Botan::DER_Encoder::end_explicit (  ) 

Definition at line 174 of file der_enc.cpp.

References end_cons().

Referenced by Botan::X509::create_cert_req(), and Botan::AlternativeName::encode_into().

00175    {
00176    return end_cons();
00177    }

SecureVector< byte > Botan::DER_Encoder::get_contents (  ) 

Definition at line 123 of file der_enc.cpp.

References Botan::MemoryRegion< T >::destroy().

Referenced by Botan::X509::create_cert_req(), encode_if(), and Botan::CMS_Encoder::get_contents().

00124    {
00125    if(subsequences.size() != 0)
00126       throw Invalid_State("DER_Encoder: Sequence hasn't been marked done");
00127 
00128    SecureVector<byte> retval;
00129    retval = contents;
00130    contents.destroy();
00131    return retval;
00132    }

DER_Encoder & Botan::DER_Encoder::raw_bytes ( const MemoryRegion< byte > &  val  ) 

Definition at line 182 of file der_enc.cpp.

References Botan::MemoryRegion< T >::begin(), raw_bytes(), and Botan::MemoryRegion< T >::size().

00183    {
00184    return raw_bytes(val.begin(), val.size());
00185    }

DER_Encoder & Botan::DER_Encoder::raw_bytes ( const byte  bytes[],
u32bit  length 
)

Definition at line 190 of file der_enc.cpp.

References Botan::MemoryRegion< T >::append().

Referenced by add_object(), Botan::X509::create_cert_req(), Botan::CMS_Encoder::digest(), encode_if(), Botan::X509_DN::encode_into(), Botan::Attribute::encode_into(), Botan::AlgorithmIdentifier::encode_into(), Botan::CMS_Encoder::encrypt(), end_cons(), raw_bytes(), and Botan::CMS_Encoder::sign().

00191    {
00192    if(subsequences.size())
00193       subsequences[subsequences.size()-1].add_bytes(bytes, length);
00194    else
00195       contents.append(bytes, length);
00196 
00197    return (*this);
00198    }

DER_Encoder & Botan::DER_Encoder::start_cons ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag = UNIVERSAL 
)

DER_Encoder & Botan::DER_Encoder::start_explicit ( u16bit  type_no  ) 

Definition at line 161 of file der_enc.cpp.

References Botan::CONTEXT_SPECIFIC, Botan::SET, and start_cons().

Referenced by Botan::X509::create_cert_req(), Botan::AlternativeName::encode_into(), and Botan::CMS_Encoder::encrypt().

00162    {
00163    ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
00164 
00165    if(type_tag == SET)
00166       throw Internal_Error("DER_Encoder.start_explicit(SET); cannot perform");
00167 
00168    return start_cons(type_tag, CONTEXT_SPECIFIC);
00169    }


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

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