Botan 1.10.17
Botan::DER_Encoder Class Reference

#include <der_enc.h>

Public Member Functions

DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, byte val)
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 MemoryRegion< byte > &rep)
DER_Encoderadd_object (ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string &str)
DER_Encoderencode (bool b)
DER_Encoderencode (bool b, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (const ASN1_Object &obj)
DER_Encoderencode (const BigInt &n)
DER_Encoderencode (const BigInt &n, 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 byte val[], size_t len, ASN1_Tag real_type)
DER_Encoderencode (const MemoryRegion< byte > &v, ASN1_Tag real_type)
DER_Encoderencode (const MemoryRegion< byte > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode (size_t s)
DER_Encoderencode (size_t s, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
DER_Encoderencode_if (bool pred, DER_Encoder &enc)
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 byte val[], size_t len)
DER_Encoderraw_bytes (const MemoryRegion< 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

◆ add_object() [1/4]

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

Definition at line 382 of file der_enc.cpp.

384 {
385 return add_object(type_tag, class_tag, &rep, 1);
386 }
DER_Encoder & add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const byte rep[], size_t length)
Definition der_enc.cpp:346

References add_object().

◆ add_object() [2/4]

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

Definition at line 346 of file der_enc.cpp.

348 {
349 SecureVector<byte> buffer;
350 buffer += encode_tag(type_tag, class_tag);
351 buffer += encode_length(length);
352 buffer += std::make_pair(rep, length);
353
354 return raw_bytes(buffer);
355 }
DER_Encoder & raw_bytes(const byte val[], size_t len)
Definition der_enc.cpp:188

References add_object(), and raw_bytes().

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

◆ add_object() [3/4]

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

Definition at line 360 of file der_enc.cpp.

362 {
363 const byte* rep = &rep_buf[0];
364 const size_t rep_len = rep_buf.size();
365 return add_object(type_tag, class_tag, rep, rep_len);
366 }

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

◆ add_object() [4/4]

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

Definition at line 371 of file der_enc.cpp.

373 {
374 const byte* rep = reinterpret_cast<const byte*>(rep_str.data());
375 const size_t rep_len = rep_str.size();
376 return add_object(type_tag, class_tag, rep, rep_len);
377 }

References add_object().

◆ encode() [1/11]

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

Definition at line 209 of file der_enc.cpp.

210 {
211 return encode(is_true, BOOLEAN, UNIVERSAL);
212 }
DER_Encoder & encode(bool b)
Definition der_enc.cpp:209
@ BOOLEAN
Definition asn1_int.h:28
@ UNIVERSAL
Definition asn1_int.h:20

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

Referenced by Botan::PKCS8::BER_encode(), Botan::PKCS8::BER_encode(), Botan::X509::BER_encode(), Botan::X509_Object::BER_encode(), Botan::CVC_EAC::create_ado_req(), Botan::X509::create_cert_req(), Botan::CVC_EAC::create_cvc_req(), Botan::DL_Group::DER_encode(), Botan::EC_Group::DER_encode(), Botan::ECDSA_Signature::DER_encode(), Botan::CMS_Encoder::digest(), encode(), encode(), encode(), encode(), encode(), encode(), encode(), encode(), encode(), encode(), encode(), Botan::EAC1_1_gen_CVC< Derived >::encode(), Botan::AlgorithmIdentifier::encode_into(), Botan::AlternativeName::encode_into(), Botan::Attribute::encode_into(), Botan::CRL_Entry::encode_into(), Botan::Extensions::encode_into(), encode_list(), encode_optional(), Botan::CMS_Encoder::encrypt(), Botan::make_cvc_cert(), Botan::EAC1_1_ADO::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), Botan::X509_Object::make_signed(), Botan::DL_Scheme_PrivateKey::pkcs8_private_key(), Botan::EC_PrivateKey::pkcs8_private_key(), Botan::IF_Scheme_PrivateKey::pkcs8_private_key(), Botan::CMS_Encoder::sign(), Botan::DL_Scheme_PublicKey::x509_subject_public_key(), and Botan::IF_Scheme_PublicKey::x509_subject_public_key().

◆ encode() [2/11]

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

Definition at line 252 of file der_enc.cpp.

254 {
255 byte val = is_true ? 0xFF : 0x00;
256 return add_object(type_tag, class_tag, &val, 1);
257 }

References add_object(), and encode().

◆ encode() [3/11]

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

Definition at line 337 of file der_enc.cpp.

338 {
339 obj.encode_into(*this);
340 return (*this);
341 }

References encode(), and Botan::ASN1_Object::encode_into().

◆ encode() [4/11]

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

Definition at line 225 of file der_enc.cpp.

226 {
227 return encode(n, INTEGER, UNIVERSAL);
228 }
@ INTEGER
Definition asn1_int.h:29

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

◆ encode() [5/11]

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

Definition at line 271 of file der_enc.cpp.

273 {
274 if(n == 0)
275 return add_object(type_tag, class_tag, 0);
276
277 bool extra_zero = (n.bits() % 8 == 0);
278 SecureVector<byte> contents(extra_zero + n.bytes());
279 BigInt::encode(&contents[extra_zero], n);
280 if(n < 0)
281 {
282 for(size_t i = 0; i != contents.size(); ++i)
283 contents[i] = ~contents[i];
284 for(size_t i = contents.size(); i > 0; --i)
285 if(++contents[i-1])
286 break;
287 }
288
289 return add_object(type_tag, class_tag, contents);
290 }
static SecureVector< byte > encode(const BigInt &n, Base base=Binary)
Definition big_code.cpp:64

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

◆ encode() [6/11]

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 306 of file der_enc.cpp.

309 {
310 if(real_type != OCTET_STRING && real_type != BIT_STRING)
311 throw Invalid_Argument("DER_Encoder: Invalid tag for byte/bit string");
312
313 if(real_type == BIT_STRING)
314 {
315 SecureVector<byte> encoded;
316 encoded.push_back(0);
317 encoded += std::make_pair(bytes, length);
318 return add_object(type_tag, class_tag, encoded);
319 }
320 else
321 return add_object(type_tag, class_tag, bytes, length);
322 }
std::invalid_argument Invalid_Argument
Definition exceptn.h:20
@ BIT_STRING
Definition asn1_int.h:30
@ OCTET_STRING
Definition asn1_int.h:31

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

◆ encode() [7/11]

DER_Encoder & Botan::DER_Encoder::encode ( const byte val[],
size_t len,
ASN1_Tag real_type )

Definition at line 243 of file der_enc.cpp.

245 {
246 return encode(bytes, length, real_type, real_type, UNIVERSAL);
247 }

References encode(), and Botan::UNIVERSAL.

◆ encode() [8/11]

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

Definition at line 233 of file der_enc.cpp.

235 {
236 return encode(&bytes[0], bytes.size(),
237 real_type, real_type, UNIVERSAL);
238 }

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

◆ encode() [9/11]

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

Definition at line 295 of file der_enc.cpp.

298 {
299 return encode(&bytes[0], bytes.size(),
300 real_type, type_tag, class_tag);
301 }

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

◆ encode() [10/11]

DER_Encoder & Botan::DER_Encoder::encode ( size_t s)

Definition at line 217 of file der_enc.cpp.

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

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

◆ encode() [11/11]

DER_Encoder & Botan::DER_Encoder::encode ( size_t s,
ASN1_Tag type_tag,
ASN1_Tag class_tag = CONTEXT_SPECIFIC )

Definition at line 262 of file der_enc.cpp.

264 {
265 return encode(BigInt(n), type_tag, class_tag);
266 }

References encode().

◆ encode_if()

DER_Encoder & Botan::DER_Encoder::encode_if ( bool pred,
DER_Encoder & enc )

Definition at line 327 of file der_enc.cpp.

328 {
329 if(cond)
330 return raw_bytes(codec.get_contents());
331 return (*this);
332 }

References encode_if(), get_contents(), and raw_bytes().

Referenced by encode_if().

◆ encode_list()

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

Definition at line 75 of file der_enc.h.

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

References encode().

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

◆ encode_null()

DER_Encoder & Botan::DER_Encoder::encode_null ( )

Definition at line 201 of file der_enc.cpp.

202 {
203 return add_object(NULL_TAG, UNIVERSAL, 0, 0);
204 }
@ NULL_TAG
Definition asn1_int.h:32

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

Referenced by Botan::EC_Group::DER_encode(), and encode_null().

◆ encode_optional()

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

Definition at line 67 of file der_enc.h.

68 {
69 if(value != default_value)
70 encode(value);
71 return (*this);
72 }

References encode().

Referenced by Botan::Extensions::encode_into().

◆ end_cons()

DER_Encoder & Botan::DER_Encoder::end_cons ( )

◆ end_explicit()

DER_Encoder & Botan::DER_Encoder::end_explicit ( )

Definition at line 172 of file der_enc.cpp.

173 {
174 return end_cons();
175 }
DER_Encoder & end_cons()
Definition der_enc.cpp:145

References end_cons(), and end_explicit().

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

◆ get_contents()

◆ raw_bytes() [1/2]

◆ raw_bytes() [2/2]

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

Definition at line 180 of file der_enc.cpp.

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

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

◆ start_cons()

◆ start_explicit()

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

Definition at line 159 of file der_enc.cpp.

160 {
161 ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
162
163 if(type_tag == SET)
164 throw Internal_Error("DER_Encoder.start_explicit(SET); cannot perform");
165
166 return start_cons(type_tag, CONTEXT_SPECIFIC);
167 }
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition der_enc.cpp:135
ASN1_Tag
Definition asn1_int.h:19
@ CONTEXT_SPECIFIC
Definition asn1_int.h:22
@ SET
Definition asn1_int.h:36
Internal_Error(const std::string &err)
Definition exceptn.h:47

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

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


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