Botan  2.6.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 BER_Object &obj)
 
 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/6]

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

Definition at line 269 of file ber_dec.cpp.

Referenced by decode_optional().

270  {
271  m_source = &src;
272  }

◆ BER_Decoder() [2/6]

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

Definition at line 277 of file ber_dec.cpp.

278  {
279  m_data_src.reset(new DataSource_Memory(data, length));
280  m_source = m_data_src.get();
281  }

◆ BER_Decoder() [3/6]

Botan::BER_Decoder::BER_Decoder ( const BER_Object obj)
explicit

Definition at line 262 of file ber_dec.cpp.

262  : BER_Decoder(obj.bits(), obj.length())
263  {
264  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:269

◆ BER_Decoder() [4/6]

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

Definition at line 286 of file ber_dec.cpp.

287  {
288  m_data_src.reset(new DataSource_Memory(data));
289  m_source = m_data_src.get();
290  }

◆ BER_Decoder() [5/6]

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

Definition at line 295 of file ber_dec.cpp.

296  {
297  m_data_src.reset(new DataSource_Memory(data.data(), data.size()));
298  m_source = m_data_src.get();
299  }

◆ BER_Decoder() [6/6]

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

Definition at line 304 of file ber_dec.cpp.

305  {
306  m_source = other.m_source;
307 
308  // take ownership
309  std::swap(m_data_src, other.m_data_src);
310  m_parent = other.m_parent;
311  }

Member Function Documentation

◆ decode() [1/10]

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

◆ decode() [2/10]

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

Definition at line 346 of file ber_dec.cpp.

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

347  {
348  return decode(out, INTEGER, UNIVERSAL);
349  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338

◆ decode() [3/10]

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

Definition at line 354 of file ber_dec.cpp.

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

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

◆ 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::PEM_Code::decode(), and Botan::UNIVERSAL.

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

◆ decode() [5/10]

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

Definition at line 377 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::BER_Object::bits(), get_next_object(), and Botan::BER_Object::length().

379  {
380  BER_Object obj = get_next_object();
381  obj.assert_is_a(type_tag, class_tag);
382 
383  if(obj.length() != 1)
384  throw BER_Decoding_Error("BER boolean value had invalid size");
385 
386  out = (obj.bits()[0]) ? true : false;
387  return (*this);
388  }
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ 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 393 of file ber_dec.cpp.

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

396  {
397  BigInt integer;
398  decode(integer, type_tag, class_tag);
399 
400  if(integer.bits() > 32)
401  throw BER_Decoding_Error("Decoded integer value larger than expected");
402 
403  out = 0;
404  for(size_t i = 0; i != 4; ++i)
405  out = (out << 8) | integer.byte_at(3-i);
406 
407  return (*this);
408  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338

◆ 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 436 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::BER_Object::bits(), Botan::BigInt::flip_sign(), get_next_object(), and Botan::BER_Object::length().

439  {
440  BER_Object obj = get_next_object();
441  obj.assert_is_a(type_tag, class_tag);
442 
443  if(obj.length() == 0)
444  {
445  out = 0;
446  }
447  else
448  {
449  const bool negative = (obj.bits()[0] & 0x80) ? true : false;
450 
451  if(negative)
452  {
453  secure_vector<uint8_t> vec(obj.bits(), obj.bits() + obj.length());
454  for(size_t i = obj.length(); i > 0; --i)
455  if(vec[i-1]--)
456  break;
457  for(size_t i = 0; i != obj.length(); ++i)
458  vec[i] = ~vec[i];
459  out = BigInt(vec.data(), vec.size());
460  out.flip_sign();
461  }
462  else
463  {
464  out = BigInt(obj.bits(), obj.length());
465  }
466  }
467 
468  return (*this);
469  }
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ 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 516 of file ber_dec.cpp.

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

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

◆ 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 505 of file ber_dec.cpp.

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

508  {
509  if(real_type != OCTET_STRING && real_type != BIT_STRING)
510  throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
511 
512  asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
513  return (*this);
514  }
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ 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 316 of file ber_dec.cpp.

References Botan::ASN1_Object::decode_from().

318  {
319  obj.decode_from(*this);
320  return (*this);
321  }

◆ 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_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:338
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 413 of file ber_dec.cpp.

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

416  {
417  if(T_bytes > 8)
418  throw BER_Decoding_Error("Can't decode small integer over 8 bytes");
419 
420  BigInt integer;
421  decode(integer, type_tag, class_tag);
422 
423  if(integer.bits() > 8*T_bytes)
424  throw BER_Decoding_Error("Decoded integer value larger than expected");
425 
426  uint64_t out = 0;
427  for(size_t i = 0; i != 8; ++i)
428  out = (out << 8) | integer.byte_at(7-i);
429 
430  return out;
431  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338

◆ 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 T.

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:413
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 290 of file ber_dec.h.

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

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

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

◆ decode_null()

BER_Decoder & Botan::BER_Decoder::decode_null ( )

Definition at line 326 of file ber_dec.cpp.

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

327  {
328  BER_Object obj = get_next_object();
329  obj.assert_is_a(NULL_TAG, UNIVERSAL);
330  if(obj.length() > 0)
331  throw BER_Decoding_Error("NULL object had nonzero size");
332  return (*this);
333  }
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ decode_octet_string_bigint()

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

Definition at line 359 of file ber_dec.cpp.

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

360  {
361  secure_vector<uint8_t> out_vec;
362  decode(out_vec, OCTET_STRING);
363  out = BigInt::decode(out_vec.data(), out_vec.size());
364  return (*this);
365  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338
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 232 of file ber_dec.h.

References BER_Decoder(), Botan::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, decode(), get_next_object(), Botan::BER_Object::is_a(), and push_back().

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

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

◆ 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 262 of file ber_dec.h.

References decode(), get_next_object(), Botan::BER_Object::is_a(), and push_back().

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

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

◆ 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::CONSTRUCTED, Botan::CONTEXT_SPECIFIC, Botan::PEM_Code::decode(), decode(), Botan::BER_Object::is_a(), and verify_end().

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

183  {
184  BER_Object obj = get_next_object();
185 
186  ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
187 
188  if(obj.is_a(type_tag, class_tag))
189  {
190  if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
191  BER_Decoder(obj).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:269
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:229
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338
ASN1_Tag
Definition: asn1_obj.h:22
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ discard_remaining()

BER_Decoder & Botan::BER_Decoder::discard_remaining ( )

Definition at line 173 of file ber_dec.cpp.

References Botan::DataSource::read_byte().

Referenced by Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), and Botan::Ed25519_PrivateKey::Ed25519_PrivateKey().

174  {
175  uint8_t buf;
176  while(m_source->read_byte(buf))
177  {}
178  return (*this);
179  }
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 220 of file ber_dec.cpp.

References get_next_object().

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

221  {
222  ber = get_next_object();
223  return (*this);
224  }
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ get_next_object()

BER_Object Botan::BER_Decoder::get_next_object ( )

Definition at line 184 of file ber_dec.cpp.

References Botan::DataSource::check_available(), Botan::EOC, Botan::BER_Object::is_set(), Botan::DataSource::read(), and Botan::BER_Object::tagging().

Referenced by decode(), Botan::ASN1_String::decode_from(), Botan::OID::decode_from(), Botan::AlternativeName::decode_from(), Botan::X509_Time::decode_from(), Botan::GeneralName::decode_from(), decode_null(), decode_optional(), decode_optional_implicit(), get_next(), and start_cons().

185  {
186  BER_Object next;
187 
188  if(m_pushed.is_set())
189  {
190  std::swap(next, m_pushed);
191  return next;
192  }
193 
194  for(;;)
195  {
196  ASN1_Tag type_tag, class_tag;
197  decode_tag(m_source, type_tag, class_tag);
198  next.set_tagging(type_tag, class_tag);
199  if(next.is_set() == false) // no more objects
200  return next;
201 
202  size_t field_size;
203  const size_t length = decode_length(m_source, field_size, ALLOWED_EOC_NESTINGS);
204  if(!m_source->check_available(length))
205  throw BER_Decoding_Error("Value truncated");
206 
207  uint8_t* out = next.mutable_bits(length);
208  if(m_source->read(out, length) != length)
209  throw BER_Decoding_Error("Value truncated");
210 
211  if(next.tagging() == EOC)
212  continue;
213  else
214  break;
215  }
216 
217  return next;
218  }
virtual bool check_available(size_t n)=0
ASN1_Tag
Definition: asn1_obj.h:22
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
bool is_set() const
Definition: asn1_obj.h:93

◆ get_next_octet_string()

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

Definition at line 367 of file ber_dec.cpp.

References decode(), and Botan::OCTET_STRING.

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

368  {
369  std::vector<uint8_t> out_vec;
370  decode(out_vec, OCTET_STRING);
371  return out_vec;
372  }
BER_Decoder & decode(bool &v)
Definition: ber_dec.cpp:338

◆ 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::BER_Object::bits(), Botan::copy_mem(), Botan::BER_Object::length(), T, and Botan::ASN1::to_string().

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.length() != sizeof(T))
58  throw BER_Decoding_Error(
59  "Size mismatch. Object value size is " +
60  std::to_string(obj.length()) +
61  "; Output type size is " +
62  std::to_string(sizeof(T)));
63 
64  copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length());
65 
66  return (*this);
67  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:145
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:108
BER_Object get_next_object()
Definition: ber_dec.cpp:184
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 229 of file ber_dec.cpp.

References Botan::BER_Object::is_set().

Referenced by decode_list(), decode_optional(), decode_optional_implicit(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), and raw_bytes().

230  {
231  if(m_pushed.is_set())
232  throw Invalid_State("BER_Decoder: Only one push back is allowed");
233  m_pushed = obj;
234  }
bool is_set() const
Definition: asn1_obj.h:93

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

Referenced by Botan::Attribute::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::X509_DN::decode_from(), Botan::X509_Object::decode_from(), 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 239 of file ber_dec.cpp.

References Botan::BER_Object::assert_is_a(), Botan::BER_Object::bits(), Botan::CONSTRUCTED, get_next_object(), and Botan::BER_Object::length().

Referenced by Botan::PK_Verifier::check_signature(), Botan::Attribute::decode_from(), Botan::AlternativeName::decode_from(), Botan::AlgorithmIdentifier::decode_from(), Botan::OCSP::CertID::decode_from(), Botan::X509_DN::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(), 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(), and Botan::TLS::Session::Session().

241  {
242  BER_Object obj = get_next_object();
243  obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED));
244 
245  BER_Decoder result(obj.bits(), obj.length());
246  result.m_parent = this;
247  return result;
248  }
BER_Decoder(DataSource &)
Definition: ber_dec.cpp:269
ASN1_Tag
Definition: asn1_obj.h:22
BER_Object get_next_object()
Definition: ber_dec.cpp:184

◆ verify_end()

BER_Decoder & Botan::BER_Decoder::verify_end ( )

Definition at line 163 of file ber_dec.cpp.

References Botan::DataSource::end_of_data(), and Botan::BER_Object::is_set().

Referenced by Botan::AlternativeName::decode_from(), Botan::Extensions::decode_from(), decode_optional_string(), and Botan::TLS::Session::Session().

164  {
165  if(!m_source->end_of_data() || m_pushed.is_set())
166  throw Invalid_State("BER_Decoder::verify_end called, but data remains");
167  return (*this);
168  }
virtual bool end_of_data() const =0
bool is_set() const
Definition: asn1_obj.h:93

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