Botan  1.11.15
Classes | Public Member Functions
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 type_tag, ASN1_Tag class_tag, const byte rep[], size_t length)
DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const std::vector< byte > &rep)
DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const secure_vector< byte > &rep)
DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string &str)
DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, byte val)
DER_Encoderencode (bool b)
DER_Encoderencode (size_t s)
DER_Encoderencode (const BigInt &n)
DER_Encoderencode (const secure_vector< byte > &v, ASN1_Tag real_type)
DER_Encoderencode (const std::vector< byte > &v, ASN1_Tag real_type)
DER_Encoderencode (const byte val[], size_t len, ASN1_Tag real_type)
DER_Encoderencode (bool b, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (size_t s, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const BigInt &n, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const std::vector< byte > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const secure_vector< byte > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const byte v[], size_t len, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const ASN1_Object &obj)
DER_Encoderencode_if (bool pred, DER_Encoder &enc)
DER_Encoderencode_if (bool pred, const ASN1_Object &obj)
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 ()
secure_vector< byteget_contents ()
std::vector< byteget_contents_unlocked ()
DER_Encoderraw_bytes (const byte val[], size_t len)
DER_Encoderraw_bytes (const secure_vector< byte > &val)
DER_Encoderraw_bytes (const std::vector< byte > &val)
DER_Encoderstart_cons (ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
DER_Encoderstart_explicit (u16bit type_tag)

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,
const byte  rep[],
size_t  length 
)

Definition at line 379 of file der_enc.cpp.

References raw_bytes().

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

   {
   secure_vector<byte> buffer;
   buffer += encode_tag(type_tag, class_tag);
   buffer += encode_length(length);
   buffer += std::make_pair(rep, length);

   return raw_bytes(buffer);
   }
DER_Encoder& Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const std::vector< byte > &  rep 
) [inline]

Definition at line 99 of file der_enc.h.

         {
         return add_object(type_tag, class_tag, &rep[0], rep.size());
         }
DER_Encoder& Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const secure_vector< byte > &  rep 
) [inline]

Definition at line 105 of file der_enc.h.

         {
         return add_object(type_tag, class_tag, &rep[0], rep.size());
         }
DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const std::string &  str 
)

Definition at line 393 of file der_enc.cpp.

References add_object().

   {
   const byte* rep = reinterpret_cast<const byte*>(rep_str.data());
   const size_t rep_len = rep_str.size();
   return add_object(type_tag, class_tag, rep, rep_len);
   }
DER_Encoder & Botan::DER_Encoder::add_object ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
byte  val 
)

Definition at line 404 of file der_enc.cpp.

References add_object().

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

Definition at line 222 of file der_enc.cpp.

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

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

Definition at line 230 of file der_enc.cpp.

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

   {
   return encode(n, INTEGER, UNIVERSAL);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const secure_vector< byte > &  v,
ASN1_Tag  real_type 
)

Definition at line 238 of file der_enc.cpp.

References encode(), and Botan::UNIVERSAL.

   {
   return encode(&bytes[0], bytes.size(),
                 real_type, real_type, UNIVERSAL);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const std::vector< byte > &  v,
ASN1_Tag  real_type 
)

Definition at line 248 of file der_enc.cpp.

References encode(), and Botan::UNIVERSAL.

   {
   return encode(&bytes[0], bytes.size(),
                 real_type, real_type, UNIVERSAL);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const byte  val[],
size_t  len,
ASN1_Tag  real_type 
)

Definition at line 258 of file der_enc.cpp.

References encode(), and Botan::UNIVERSAL.

   {
   return encode(bytes, length, real_type, real_type, UNIVERSAL);
   }
DER_Encoder & Botan::DER_Encoder::encode ( bool  b,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 267 of file der_enc.cpp.

References add_object().

   {
   byte val = is_true ? 0xFF : 0x00;
   return add_object(type_tag, class_tag, &val, 1);
   }
DER_Encoder & Botan::DER_Encoder::encode ( size_t  s,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 277 of file der_enc.cpp.

References encode().

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

Definition at line 286 of file der_enc.cpp.

References add_object(), Botan::BigInt::bits(), Botan::BigInt::bytes(), and encode().

   {
   if(n == 0)
      return add_object(type_tag, class_tag, 0);

   bool extra_zero = (n.bits() % 8 == 0);
   secure_vector<byte> contents(extra_zero + n.bytes());
   BigInt::encode(&contents[extra_zero], n);
   if(n < 0)
      {
      for(size_t i = 0; i != contents.size(); ++i)
         contents[i] = ~contents[i];
      for(size_t i = contents.size(); i > 0; --i)
         if(++contents[i-1])
            break;
      }

   return add_object(type_tag, class_tag, contents);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const std::vector< byte > &  v,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 321 of file der_enc.cpp.

References encode().

   {
   return encode(&bytes[0], bytes.size(),
                 real_type, type_tag, class_tag);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const secure_vector< byte > &  v,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 310 of file der_enc.cpp.

References encode().

   {
   return encode(&bytes[0], bytes.size(),
                 real_type, type_tag, class_tag);
   }
DER_Encoder & Botan::DER_Encoder::encode ( const byte  v[],
size_t  len,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 332 of file der_enc.cpp.

References add_object(), Botan::BIT_STRING, and Botan::OCTET_STRING.

   {
   if(real_type != OCTET_STRING && real_type != BIT_STRING)
      throw Invalid_Argument("DER_Encoder: Invalid tag for byte/bit string");

   if(real_type == BIT_STRING)
      {
      secure_vector<byte> encoded;
      encoded.push_back(0);
      encoded += std::make_pair(bytes, length);
      return add_object(type_tag, class_tag, encoded);
      }
   else
      return add_object(type_tag, class_tag, bytes, length);
   }

Definition at line 370 of file der_enc.cpp.

References Botan::ASN1_Object::encode_into().

   {
   obj.encode_into(*this);
   return (*this);
   }

Definition at line 353 of file der_enc.cpp.

References get_contents(), and raw_bytes().

   {
   if(cond)
      return raw_bytes(codec.get_contents());
   return (*this);
   }
DER_Encoder & Botan::DER_Encoder::encode_if ( bool  pred,
const ASN1_Object obj 
)

Definition at line 360 of file der_enc.cpp.

References encode().

   {
   if(cond)
      encode(obj);
   return (*this);
   }
template<typename T >
DER_Encoder& Botan::DER_Encoder::encode_list ( const std::vector< T > &  values) [inline]

Definition at line 85 of file der_enc.h.

References Botan::PEM_Code::encode().

Referenced by Botan::PK_Signer::signature().

         {
         for(size_t i = 0; i != values.size(); ++i)
            encode(values[i]);
         return (*this);
         }

Definition at line 206 of file der_enc.cpp.

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

Referenced by Botan::EC_Group::DER_encode().

   {
   return add_object(NULL_TAG, UNIVERSAL, nullptr, 0);
   }
template<typename T >
DER_Encoder& Botan::DER_Encoder::encode_optional ( const T &  value,
const T &  default_value 
) [inline]

Definition at line 77 of file der_enc.h.

References Botan::PEM_Code::encode().

         {
         if(value != default_value)
            encode(value);
         return (*this);
         }
secure_vector< byte > Botan::DER_Encoder::get_contents ( )

Definition at line 122 of file der_enc.cpp.

Referenced by Botan::CVC_EAC::create_ado_req(), Botan::X509::create_cert_req(), Botan::TLS::Session::DER_encode(), encode_if(), Botan::Curve25519_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::DL_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), and Botan::McEliece_PrivateKey::pkcs8_private_key().

   {
   if(subsequences.size() != 0)
      throw Invalid_State("DER_Encoder: Sequence hasn't been marked done");

   secure_vector<byte> output;
   std::swap(output, contents);
   return output;
   }
DER_Encoder & Botan::DER_Encoder::raw_bytes ( const byte  val[],
size_t  len 
)
DER_Encoder & Botan::DER_Encoder::raw_bytes ( const secure_vector< byte > &  val)

Definition at line 180 of file der_enc.cpp.

References raw_bytes().

   {
   return raw_bytes(&val[0], val.size());
   }
DER_Encoder & Botan::DER_Encoder::raw_bytes ( const std::vector< byte > &  val)

Definition at line 185 of file der_enc.cpp.

References raw_bytes().

   {
   return raw_bytes(&val[0], val.size());
   }

Definition at line 159 of file der_enc.cpp.

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

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

   {
   ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);

   if(type_tag == SET)
      throw Internal_Error("DER_Encoder.start_explicit(SET); cannot perform");

   return start_cons(type_tag, CONTEXT_SPECIFIC);
   }

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