Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::BER_Decoder Class Referencefinal

#include <ber_dec.h>

Public Member Functions

 BER_Decoder (DataSource &)
 
 BER_Decoder (const uint8_t[], size_t)
 
 BER_Decoder (const secure_vector< uint8_t > &)
 
 BER_Decoder (const std::vector< uint8_t > &vec)
 
 BER_Decoder (const BER_Decoder &)
 
BER_Decoderdecode (bool &v)
 
BER_Decoderdecode (size_t &v)
 
BER_Decoderdecode (class BigInt &v)
 
template<typename Alloc >
BER_Decoderdecode (std::vector< uint8_t, Alloc > &out, ASN1_Tag real_type)
 
BER_Decoderdecode (bool &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdecode (size_t &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdecode (class BigInt &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdecode (std::vector< uint8_t > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdecode (secure_vector< uint8_t > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdecode (class ASN1_Object &obj, ASN1_Tag type_tag=NO_OBJECT, ASN1_Tag class_tag=NO_OBJECT)
 
template<typename T >
BER_Decoderdecode_and_check (const T &expected, const std::string &error_msg)
 
uint64_t decode_constrained_integer (ASN1_Tag type_tag, ASN1_Tag class_tag, size_t T_bytes)
 
template<typename T >
BER_Decoderdecode_integer_type (T &out)
 
template<typename T >
BER_Decoderdecode_integer_type (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
template<typename T >
BER_Decoderdecode_list (std::vector< T > &out, ASN1_Tag type_tag=SEQUENCE, ASN1_Tag class_tag=UNIVERSAL)
 
BER_Decoderdecode_null ()
 
BER_Decoderdecode_octet_string_bigint (class BigInt &b)
 
template<typename T >
BER_Decoderdecode_optional (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag, const T &default_value=T())
 
template<typename T >
BER_Decoderdecode_optional_implicit (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag, ASN1_Tag real_type, ASN1_Tag real_class, const T &default_value=T())
 
template<typename Alloc >
BER_Decoderdecode_optional_string (std::vector< uint8_t, Alloc > &out, ASN1_Tag real_type, uint16_t type_no, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
BER_Decoderdiscard_remaining ()
 
BER_Decoderend_cons ()
 
BER_Decoderget_next (BER_Object &ber)
 
BER_Object get_next_object ()
 
std::vector< uint8_t > get_next_octet_string ()
 
template<typename T >
BER_Decoderget_next_value (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
 
bool more_items () const
 
BER_Decoderoperator= (const BER_Decoder &)=delete
 
void push_back (const BER_Object &obj)
 
template<typename Alloc >
BER_Decoderraw_bytes (std::vector< uint8_t, Alloc > &out)
 
BER_Decoder start_cons (ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
 
BER_Decoderverify_end ()
 

Detailed Description

BER Decoding Object

Definition at line 19 of file ber_dec.h.

Constructor & Destructor Documentation

◆ BER_Decoder() [1/5]

Botan::BER_Decoder::BER_Decoder ( DataSource src)
explicit

Definition at line 277 of file ber_dec.cpp.

References Botan::NO_OBJECT.

278  {
279  m_source = &src;
280  m_pushed.type_tag = m_pushed.class_tag = NO_OBJECT;
281  m_parent = nullptr;
282  }
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ BER_Decoder() [2/5]

Botan::BER_Decoder::BER_Decoder ( const uint8_t  data[],
size_t  length 
)

Definition at line 287 of file ber_dec.cpp.

References Botan::NO_OBJECT.

288  {
289  m_data_src.reset(new DataSource_Memory(data, length));
290  m_source = m_data_src.get();
291  m_pushed.type_tag = m_pushed.class_tag = NO_OBJECT;
292  m_parent = nullptr;
293  }
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ BER_Decoder() [3/5]

Botan::BER_Decoder::BER_Decoder ( const secure_vector< uint8_t > &  data)
explicit

Definition at line 298 of file ber_dec.cpp.

References Botan::NO_OBJECT.

299  {
300  m_data_src.reset(new DataSource_Memory(data));
301  m_source = m_data_src.get();
302  m_pushed.type_tag = m_pushed.class_tag = NO_OBJECT;
303  m_parent = nullptr;
304  }
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ BER_Decoder() [4/5]

Botan::BER_Decoder::BER_Decoder ( const std::vector< uint8_t > &  vec)
explicit

Definition at line 309 of file ber_dec.cpp.

References Botan::NO_OBJECT.

310  {
311  m_data_src.reset(new DataSource_Memory(data.data(), data.size()));
312  m_source = m_data_src.get();
313  m_pushed.type_tag = m_pushed.class_tag = NO_OBJECT;
314  m_parent = nullptr;
315  }
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ BER_Decoder() [5/5]

Botan::BER_Decoder::BER_Decoder ( const BER_Decoder other)

Definition at line 320 of file ber_dec.cpp.

References Botan::NO_OBJECT.

321  {
322  m_source = other.m_source;
323 
324  // take ownership
325  std::swap(m_data_src, other.m_data_src);
326  m_pushed.type_tag = m_pushed.class_tag = NO_OBJECT;
327  m_parent = other.m_parent;
328  }
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

Member Function Documentation

◆ decode() [1/10]

BER_Decoder & Botan::BER_Decoder::decode ( bool &  v)

Definition at line 355 of file ber_dec.cpp.

References Botan::BOOLEAN, Botan::PEM_Code::decode(), and Botan::UNIVERSAL.

Referenced by Botan::DL_Group::BER_decode(), Botan::PK_Verifier::check_signature(), Botan::Cert_Extension::CRL_Number::copy(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Attribute::decode_from(), Botan::AlternativeName::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::CRL_Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::X509_Object::decode_from(), Botan::GeneralSubtree::decode_from(), Botan::Extensions::decode_from(), Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from(), decode_list(), decode_optional(), decode_optional_string(), Botan::DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(), Botan::DL_Scheme_PublicKey::DL_Scheme_PublicKey(), Botan::EC_Group::EC_Group(), Botan::Ed25519_PrivateKey::Ed25519_PrivateKey(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), Botan::X509_CRL::is_revoked(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::PKCS10_Request::PKCS10_Request(), Botan::ASN1_Formatter::print_to_stream(), Botan::OCSP::Response::Response(), Botan::RSA_PublicKey::RSA_PublicKey(), Botan::TLS::Session::Session(), Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID(), Botan::Cert_Extension::Certificate_Policies::validate(), and Botan::X509_Certificate::X509_Certificate().

356  {
357  return decode(out, BOOLEAN, UNIVERSAL);
358  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode() [2/10]

BER_Decoder & Botan::BER_Decoder::decode ( size_t &  v)

Definition at line 363 of file ber_dec.cpp.

References Botan::PEM_Code::decode(), Botan::INTEGER, and Botan::UNIVERSAL.

364  {
365  return decode(out, INTEGER, UNIVERSAL);
366  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode() [3/10]

BER_Decoder & Botan::BER_Decoder::decode ( class BigInt v)

Definition at line 371 of file ber_dec.cpp.

References Botan::PEM_Code::decode(), Botan::INTEGER, and Botan::UNIVERSAL.

372  {
373  return decode(out, INTEGER, UNIVERSAL);
374  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode() [4/10]

template<typename Alloc >
BER_Decoder& Botan::BER_Decoder::decode ( std::vector< uint8_t, Alloc > &  out,
ASN1_Tag  real_type 
)
inline

Definition at line 91 of file ber_dec.h.

References Botan::CONTEXT_SPECIFIC, Botan::PEM_Code::decode(), Botan::NO_OBJECT, and Botan::UNIVERSAL.

92  {
93  return decode(out, real_type, real_type, UNIVERSAL);
94  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode() [5/10]

BER_Decoder & Botan::BER_Decoder::decode ( bool &  v,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 394 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), and Botan::BER_Object::value.

396  {
397  BER_Object obj = get_next_object();
398  obj.assert_is_a(type_tag, class_tag);
399 
400  if(obj.value.size() != 1)
401  throw BER_Decoding_Error("BER boolean value had invalid size");
402 
403  out = (obj.value[0]) ? true : false;
404  return (*this);
405  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode() [6/10]

BER_Decoder & Botan::BER_Decoder::decode ( size_t &  v,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 410 of file ber_dec.cpp.

References Botan::BigInt::bits(), Botan::BigInt::byte_at(), and Botan::PEM_Code::decode().

413  {
414  BigInt integer;
415  decode(integer, type_tag, class_tag);
416 
417  if(integer.bits() > 32)
418  throw BER_Decoding_Error("Decoded integer value larger than expected");
419 
420  out = 0;
421  for(size_t i = 0; i != 4; ++i)
422  out = (out << 8) | integer.byte_at(3-i);
423 
424  return (*this);
425  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode() [7/10]

BER_Decoder & Botan::BER_Decoder::decode ( class BigInt v,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 453 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::copy_mem(), Botan::BigInt::flip_sign(), Botan::OCTET_STRING, and Botan::BER_Object::value.

456  {
457  BER_Object obj = get_next_object();
458  obj.assert_is_a(type_tag, class_tag);
459 
460  if(obj.value.empty())
461  out = 0;
462  else
463  {
464  const bool negative = (obj.value[0] & 0x80) ? true : false;
465 
466  if(negative)
467  {
468  for(size_t i = obj.value.size(); i > 0; --i)
469  if(obj.value[i-1]--)
470  break;
471  for(size_t i = 0; i != obj.value.size(); ++i)
472  obj.value[i] = ~obj.value[i];
473  }
474 
475  out = BigInt(&obj.value[0], obj.value.size());
476 
477  if(negative)
478  out.flip_sign();
479  }
480 
481  return (*this);
482  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode() [8/10]

BER_Decoder & Botan::BER_Decoder::decode ( std::vector< uint8_t > &  v,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 529 of file ber_dec.cpp.

References Botan::BIT_STRING, and Botan::OCTET_STRING.

532  {
533  if(real_type != OCTET_STRING && real_type != BIT_STRING)
534  throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
535 
536  asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
537  return (*this);
538  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode() [9/10]

BER_Decoder & Botan::BER_Decoder::decode ( secure_vector< uint8_t > &  v,
ASN1_Tag  real_type,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)

Definition at line 518 of file ber_dec.cpp.

References Botan::BIT_STRING, and Botan::OCTET_STRING.

521  {
522  if(real_type != OCTET_STRING && real_type != BIT_STRING)
523  throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
524 
525  asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
526  return (*this);
527  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode() [10/10]

BER_Decoder & Botan::BER_Decoder::decode ( class ASN1_Object obj,
ASN1_Tag  type_tag = NO_OBJECT,
ASN1_Tag  class_tag = NO_OBJECT 
)

Definition at line 333 of file ber_dec.cpp.

References Botan::ASN1_Object::decode_from().

335  {
336  obj.decode_from(*this);
337  return (*this);
338  }

◆ decode_and_check()

template<typename T >
BER_Decoder& Botan::BER_Decoder::decode_and_check ( const T expected,
const std::string &  error_msg 
)
inline

Definition at line 163 of file ber_dec.h.

References Botan::PEM_Code::decode(), and T.

Referenced by Botan::EC_Group::EC_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::OCSP::Response::Response(), Botan::RSA_PrivateKey::RSA_PrivateKey(), and Botan::TLS::Session::Session().

165  {
166  T actual;
167  decode(actual);
168 
169  if(actual != expected)
170  throw Decoding_Error(error_msg);
171 
172  return (*this);
173  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355
fe T
Definition: ge.cpp:37

◆ decode_constrained_integer()

uint64_t Botan::BER_Decoder::decode_constrained_integer ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
size_t  T_bytes 
)

Definition at line 430 of file ber_dec.cpp.

References Botan::BigInt::bits(), Botan::BigInt::byte_at(), and Botan::PEM_Code::decode().

433  {
434  if(T_bytes > 8)
435  throw BER_Decoding_Error("Can't decode small integer over 8 bytes");
436 
437  BigInt integer;
438  decode(integer, type_tag, class_tag);
439 
440  if(integer.bits() > 8*T_bytes)
441  throw BER_Decoding_Error("Decoded integer value larger than expected");
442 
443  uint64_t out = 0;
444  for(size_t i = 0; i != 8; ++i)
445  out = (out << 8) | integer.byte_at(7-i);
446 
447  return out;
448  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ decode_integer_type() [1/2]

template<typename T >
BER_Decoder& Botan::BER_Decoder::decode_integer_type ( T out)
inline

Definition at line 128 of file ber_dec.h.

References Botan::INTEGER, and Botan::UNIVERSAL.

Referenced by Botan::TLS::Session::Session().

129  {
130  return decode_integer_type<T>(out, INTEGER, UNIVERSAL);
131  }

◆ decode_integer_type() [2/2]

template<typename T >
BER_Decoder& Botan::BER_Decoder::decode_integer_type ( T out,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)
inline

Definition at line 134 of file ber_dec.h.

References Botan::SEQUENCE, T, and Botan::UNIVERSAL.

137  {
138  out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out)));
139  return (*this);
140  }
uint64_t decode_constrained_integer(ASN1_Tag type_tag, ASN1_Tag class_tag, size_t T_bytes)
Definition: ber_dec.cpp:430
fe T
Definition: ge.cpp:37

◆ decode_list()

template<typename T >
BER_Decoder & Botan::BER_Decoder::decode_list ( std::vector< T > &  out,
ASN1_Tag  type_tag = SEQUENCE,
ASN1_Tag  class_tag = UNIVERSAL 
)

Definition at line 289 of file ber_dec.h.

References decode(), end_cons(), more_items(), push_back(), and T.

Referenced by Botan::Cert_Extension::CRL_Number::copy(), Botan::OCSP::Response::Response(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().

292  {
293  BER_Decoder list = start_cons(type_tag, class_tag);
294 
295  while(list.more_items())
296  {
297  T value;
298  list.decode(value);
299  vec.push_back(value);
300  }
301 
302  list.end_cons();
303 
304  return (*this);
305  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:277
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:251
fe T
Definition: ge.cpp:37

◆ decode_null()

BER_Decoder & Botan::BER_Decoder::decode_null ( )

Definition at line 343 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::NULL_TAG, Botan::UNIVERSAL, and Botan::BER_Object::value.

344  {
345  BER_Object obj = get_next_object();
346  obj.assert_is_a(NULL_TAG, UNIVERSAL);
347  if(obj.value.size())
348  throw BER_Decoding_Error("NULL object had nonzero size");
349  return (*this);
350  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode_octet_string_bigint()

BER_Decoder & Botan::BER_Decoder::decode_octet_string_bigint ( class BigInt b)

Definition at line 376 of file ber_dec.cpp.

References Botan::PEM_Code::decode(), Botan::BigInt::decode(), and Botan::OCTET_STRING.

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

377  {
378  secure_vector<uint8_t> out_vec;
379  decode(out_vec, OCTET_STRING);
380  out = BigInt::decode(out_vec.data(), out_vec.size());
381  return (*this);
382  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114

◆ decode_optional()

template<typename T >
BER_Decoder & Botan::BER_Decoder::decode_optional ( T out,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
const T default_value = T() 
)

Definition at line 230 of file ber_dec.h.

References Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::PEM_Code::decode(), decode(), Botan::BER_Object::type_tag, Botan::BER_Object::value, and verify_end().

Referenced by Botan::OCSP::SingleResponse::decode_from(), Botan::GeneralSubtree::decode_from(), Botan::Extensions::decode_from(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::X509_CRL::is_revoked(), Botan::pbes2_decrypt(), and Botan::OCSP::Response::Response().

234  {
235  BER_Object obj = get_next_object();
236 
237  if(obj.type_tag == type_tag && obj.class_tag == class_tag)
238  {
239  if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
240  BER_Decoder(obj.value).decode(out).verify_end();
241  else
242  {
243  push_back(obj);
244  decode(out, type_tag, class_tag);
245  }
246  }
247  else
248  {
249  out = default_value;
250  push_back(obj);
251  }
252 
253  return (*this);
254  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:277
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:241
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode_optional_implicit()

template<typename T >
BER_Decoder & Botan::BER_Decoder::decode_optional_implicit ( T out,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag,
ASN1_Tag  real_type,
ASN1_Tag  real_class,
const T default_value = T() 
)

Definition at line 260 of file ber_dec.h.

References Botan::BER_Object::class_tag, Botan::PEM_Code::decode(), and Botan::BER_Object::type_tag.

Referenced by Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from().

267  {
268  BER_Object obj = get_next_object();
269 
270  if(obj.type_tag == type_tag && obj.class_tag == class_tag)
271  {
272  obj.type_tag = real_type;
273  obj.class_tag = real_class;
274  push_back(obj);
275  decode(out, real_type, real_class);
276  }
277  else
278  {
279  out = default_value;
280  push_back(obj);
281  }
282 
283  return (*this);
284  }
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:241
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ decode_optional_string()

template<typename Alloc >
BER_Decoder& Botan::BER_Decoder::decode_optional_string ( std::vector< uint8_t, Alloc > &  out,
ASN1_Tag  real_type,
uint16_t  type_no,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)
inline

Definition at line 179 of file ber_dec.h.

References Botan::BER_Object::class_tag, Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::PEM_Code::decode(), decode(), Botan::BER_Object::type_tag, Botan::BER_Object::value, and verify_end().

Referenced by Botan::EC_PrivateKey::EC_PrivateKey(), Botan::OCSP::Response::Response(), Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID(), and Botan::X509_Certificate::X509_Certificate().

183  {
184  BER_Object obj = get_next_object();
185 
186  ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
187 
188  if(obj.type_tag == type_tag && obj.class_tag == class_tag)
189  {
190  if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
191  BER_Decoder(obj.value).decode(out, real_type).verify_end();
192  else
193  {
194  push_back(obj);
195  decode(out, real_type, type_tag, class_tag);
196  }
197  }
198  else
199  {
200  out.clear();
201  push_back(obj);
202  }
203 
204  return (*this);
205  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:277
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:241
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355
ASN1_Tag
Definition: asn1_obj.h:22
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ discard_remaining()

BER_Decoder & Botan::BER_Decoder::discard_remaining ( )

Definition at line 186 of file ber_dec.cpp.

Referenced by Botan::DL_Group::BER_decode(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), Botan::Ed25519_PrivateKey::Ed25519_PrivateKey(), and Botan::X509_Certificate::X509_Certificate().

187  {
188  uint8_t buf;
189  while(m_source->read_byte(buf))
190  {}
191  return (*this);
192  }
size_t read_byte(uint8_t &out)
Definition: data_src.cpp:23

◆ end_cons()

BER_Decoder & Botan::BER_Decoder::end_cons ( )

◆ get_next()

BER_Decoder & Botan::BER_Decoder::get_next ( BER_Object ber)

Definition at line 232 of file ber_dec.cpp.

Referenced by Botan::OCSP::SingleResponse::decode_from().

233  {
234  ber = get_next_object();
235  return (*this);
236  }
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ get_next_object()

BER_Object Botan::BER_Decoder::get_next_object ( )

Definition at line 197 of file ber_dec.cpp.

References Botan::BER_Object::class_tag, Botan::EOC, Botan::NO_OBJECT, Botan::BER_Object::type_tag, Botan::UNIVERSAL, and Botan::BER_Object::value.

Referenced by Botan::ASN1_String::decode_from(), Botan::OID::decode_from(), Botan::AlternativeName::decode_from(), Botan::X509_Time::decode_from(), Botan::GeneralName::decode_from(), Botan::EC_Group::EC_Group(), Botan::X509_CRL::is_revoked(), Botan::PKCS10_Request::PKCS10_Request(), Botan::ASN1_Formatter::print_to_stream(), Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID(), and Botan::Cert_Extension::Certificate_Policies::validate().

198  {
199  BER_Object next;
200 
201  if(m_pushed.type_tag != NO_OBJECT)
202  {
203  next = m_pushed;
204  m_pushed.class_tag = m_pushed.type_tag = NO_OBJECT;
205  return next;
206  }
207 
208  for(;;)
209  {
210  decode_tag(m_source, next.type_tag, next.class_tag);
211  if(next.type_tag == NO_OBJECT)
212  return next;
213 
214  size_t field_size;
215  const size_t length = decode_length(m_source, field_size, ALLOWED_EOC_NESTINGS);
216  if(!m_source->check_available(length))
217  throw BER_Decoding_Error("Value truncated");
218 
219  next.value.resize(length);
220  if(m_source->read(next.value.data(), length) != length)
221  throw BER_Decoding_Error("Value truncated");
222 
223  if(next.type_tag == EOC && next.class_tag == UNIVERSAL)
224  continue;
225  else
226  break;
227  }
228 
229  return next;
230  }
virtual bool check_available(size_t n)=0
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
ASN1_Tag class_tag
Definition: asn1_obj.h:94
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ get_next_octet_string()

std::vector< uint8_t > Botan::BER_Decoder::get_next_octet_string ( )

Definition at line 384 of file ber_dec.cpp.

References Botan::PEM_Code::decode(), and Botan::OCTET_STRING.

Referenced by Botan::OCSP::Response::Response().

385  {
386  std::vector<uint8_t> out_vec;
387  decode(out_vec, OCTET_STRING);
388  return out_vec;
389  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:355

◆ get_next_value()

template<typename T >
BER_Decoder& Botan::BER_Decoder::get_next_value ( T out,
ASN1_Tag  type_tag,
ASN1_Tag  class_tag = CONTEXT_SPECIFIC 
)
inline

Get next object and copy value to POD type Asserts value length is equal to POD type sizeof. Asserts Type tag and optional Class tag according to parameters. Copy value to POD type (struct, union, C-style array, std::array, etc.).

Parameters
outPOD type reference where to copy object value
type_tagASN1_Tag enum to assert type on object read
class_tagASN1_Tag enum to assert class on object read (default: CONTEXT_SPECIFIC)
Returns
this reference

Definition at line 48 of file ber_dec.h.

References Botan::BER_Object::assert_is_a(), Botan::copy_mem(), T, Botan::ASN1::to_string(), and Botan::BER_Object::value.

51  {
52  static_assert(std::is_pod<T>::value, "Type must be POD");
53 
54  BER_Object obj = get_next_object();
55  obj.assert_is_a(type_tag, class_tag);
56 
57  if (obj.value.size() != sizeof(T))
58  throw BER_Decoding_Error(
59  "Size mismatch. Object value size is " +
60  std::to_string(obj.value.size()) +
61  "; Output type size is " +
62  std::to_string(sizeof(T)));
63 
64  copy_mem(reinterpret_cast<uint8_t*>(&out), obj.value.data(), obj.value.size());
65 
66  return (*this);
67  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:97
BER_Object get_next_object()
Definition: ber_dec.cpp:197
fe T
Definition: ge.cpp:37

◆ more_items()

bool Botan::BER_Decoder::more_items ( ) const

◆ operator=()

BER_Decoder& Botan::BER_Decoder::operator= ( const BER_Decoder )
delete

◆ push_back()

void Botan::BER_Decoder::push_back ( const BER_Object obj)

Definition at line 241 of file ber_dec.cpp.

References Botan::NO_OBJECT.

Referenced by Botan::Cert_Extension::CRL_Number::copy(), decode_list(), Botan::X509_CRL::is_revoked(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), raw_bytes(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().

242  {
243  if(m_pushed.type_tag != NO_OBJECT)
244  throw Invalid_State("BER_Decoder: Only one push back is allowed");
245  m_pushed = obj;
246  }
ASN1_Tag type_tag
Definition: asn1_obj.h:94

◆ raw_bytes()

template<typename Alloc >
BER_Decoder& Botan::BER_Decoder::raw_bytes ( std::vector< uint8_t, Alloc > &  out)
inline

Definition at line 73 of file ber_dec.h.

References Botan::PEM_Code::decode(), and push_back().

Referenced by Botan::DER_Encoder::add_object(), Botan::Attribute::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::X509_Object::decode_from(), Botan::DER_Encoder::encode_if(), Botan::DER_Encoder::end_cons(), and Botan::OCSP::Response::Response().

74  {
75  out.clear();
76  uint8_t buf;
77  while(m_source->read_byte(buf))
78  out.push_back(buf);
79  return (*this);
80  }
size_t read_byte(uint8_t &out)
Definition: data_src.cpp:23

◆ start_cons()

BER_Decoder Botan::BER_Decoder::start_cons ( ASN1_Tag  type_tag,
ASN1_Tag  class_tag = UNIVERSAL 
)

Definition at line 251 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::CONSTRUCTED, and Botan::BER_Object::value.

Referenced by Botan::DL_Group::BER_decode(), Botan::PK_Verifier::check_signature(), Botan::Attribute::decode_from(), Botan::AlternativeName::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::CRL_Entry::decode_from(), Botan::OCSP::SingleResponse::decode_from(), Botan::X509_Object::decode_from(), Botan::GeneralSubtree::decode_from(), Botan::Extensions::decode_from(), Botan::Cert_Extension::CRL_Distribution_Points::Distribution_Point::decode_from(), Botan::EC_Group::EC_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::OCSP::Response::Response(), Botan::RSA_PrivateKey::RSA_PrivateKey(), Botan::RSA_PublicKey::RSA_PublicKey(), Botan::TLS::Session::Session(), Botan::DER_Encoder::start_explicit(), Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID(), and Botan::Cert_Extension::Certificate_Policies::validate().

253  {
254  BER_Object obj = get_next_object();
255  obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED));
256 
257  BER_Decoder result(obj.value.data(), obj.value.size());
258  result.m_parent = this;
259  return result;
260  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:277
ASN1_Tag
Definition: asn1_obj.h:22
BER_Object get_next_object()
Definition: ber_dec.cpp:197

◆ verify_end()

BER_Decoder & Botan::BER_Decoder::verify_end ( )

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