Botan 3.6.1
Crypto and TLS for C&
Botan::BER_Decoder Class Referencefinal

#include <ber_dec.h>

Public Member Functions

 BER_Decoder (BER_Object &&obj)
 
 BER_Decoder (const BER_Decoder &other)
 
 BER_Decoder (const BER_Object &obj)
 
 BER_Decoder (const secure_vector< uint8_t > &vec)
 
 BER_Decoder (const std::vector< uint8_t > &vec)
 
 BER_Decoder (const uint8_t buf[], size_t len)
 
 BER_Decoder (DataSource &src)
 
 BER_Decoder (std::span< const uint8_t > buf)
 
BER_Decoderdecode (ASN1_Object &obj, ASN1_Type type_tag=ASN1_Type::NoObject, ASN1_Class class_tag=ASN1_Class::NoObject)
 
BER_Decoderdecode (BigInt &out)
 
BER_Decoderdecode (BigInt &v, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
BER_Decoderdecode (bool &out)
 
BER_Decoderdecode (bool &v, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
BER_Decoderdecode (secure_vector< uint8_t > &v, ASN1_Type real_type, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
BER_Decoderdecode (size_t &out)
 
BER_Decoderdecode (size_t &v, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
BER_Decoderdecode (std::vector< uint8_t > &v, ASN1_Type real_type, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
template<typename Alloc >
BER_Decoderdecode (std::vector< uint8_t, Alloc > &out, ASN1_Type real_type)
 
template<typename T >
BER_Decoderdecode_and_check (const T &expected, std::string_view error_msg)
 
uint64_t decode_constrained_integer (ASN1_Type type_tag, ASN1_Class 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_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
template<typename T >
BER_Decoderdecode_list (std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
 
BER_Decoderdecode_null ()
 
BER_Decoderdecode_octet_string_bigint (BigInt &b)
 
template<typename T >
BER_Decoderdecode_optional (T &out, ASN1_Type type_tag, ASN1_Class class_tag, const T &default_value=T())
 
template<typename T >
BER_Decoderdecode_optional_implicit (T &out, ASN1_Type type_tag, ASN1_Class class_tag, ASN1_Type real_type, ASN1_Class real_class, const T &default_value=T())
 
template<typename T >
bool decode_optional_list (std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
 
template<typename Alloc >
BER_Decoderdecode_optional_string (std::vector< uint8_t, Alloc > &out, ASN1_Type real_type, ASN1_Type expected_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
template<typename Alloc >
BER_Decoderdecode_optional_string (std::vector< uint8_t, Alloc > &out, ASN1_Type real_type, uint32_t expected_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
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 >
requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
BER_Decoderget_next_value (T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
 
bool more_items () const
 
BER_Decoderoperator= (const BER_Decoder &)=delete
 
const BER_Objectpeek_next_object ()
 
void push_back (BER_Object &&obj)
 
void push_back (const BER_Object &obj)
 
template<typename Alloc >
BER_Decoderraw_bytes (std::vector< uint8_t, Alloc > &out)
 
BER_Decoder start_cons (ASN1_Type type_tag, ASN1_Class class_tag)
 
BER_Decoder start_context_specific (uint32_t tag)
 
BER_Decoder start_explicit_context_specific (uint32_t tag)
 
BER_Decoder start_sequence ()
 
BER_Decoder start_set ()
 
BER_Decoderverify_end ()
 
BER_Decoderverify_end (std::string_view err_msg)
 

Detailed Description

BER Decoding Object

Definition at line 22 of file ber_dec.h.

Constructor & Destructor Documentation

◆ BER_Decoder() [1/8]

Botan::BER_Decoder::BER_Decoder ( const uint8_t buf[],
size_t len )

Set up to BER decode the data in buf of length len

Definition at line 335 of file ber_dec.cpp.

335 {
336 m_data_src = std::make_unique<DataSource_Memory>(data, length);
337 m_source = m_data_src.get();
338}

Referenced by decode_optional(), and start_cons().

◆ BER_Decoder() [2/8]

Botan::BER_Decoder::BER_Decoder ( std::span< const uint8_t > buf)
inline

Set up to BER decode the data in buf of length len

Definition at line 32 of file ber_dec.h.

32: BER_Decoder(buf.data(), buf.size()) {}
BER_Decoder(const uint8_t buf[], size_t len)
Definition ber_dec.cpp:335

◆ BER_Decoder() [3/8]

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

Set up to BER decode the data in vec

Definition at line 343 of file ber_dec.cpp.

343 {
344 m_data_src = std::make_unique<DataSource_Memory>(data);
345 m_source = m_data_src.get();
346}

◆ BER_Decoder() [4/8]

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

Set up to BER decode the data in vec

Definition at line 351 of file ber_dec.cpp.

351 {
352 m_data_src = std::make_unique<DataSource_Memory>(data.data(), data.size());
353 m_source = m_data_src.get();
354}

◆ BER_Decoder() [5/8]

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

Set up to BER decode the data in src

Definition at line 328 of file ber_dec.cpp.

328 {
329 m_source = &src;
330}

◆ BER_Decoder() [6/8]

Botan::BER_Decoder::BER_Decoder ( const BER_Object & obj)
inline

Set up to BER decode the data in obj

Definition at line 52 of file ber_dec.h.

52: BER_Decoder(obj.bits(), obj.length()) {}

◆ BER_Decoder() [7/8]

Botan::BER_Decoder::BER_Decoder ( BER_Object && obj)
inline

Set up to BER decode the data in obj

Definition at line 57 of file ber_dec.h.

57: BER_Decoder(std::move(obj), nullptr) {}

◆ BER_Decoder() [8/8]

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

Definition at line 359 of file ber_dec.cpp.

359 {
360 m_source = other.m_source;
361
362 // take ownership
363 std::swap(m_data_src, other.m_data_src);
364 m_parent = other.m_parent;
365}

Member Function Documentation

◆ decode() [1/10]

BER_Decoder & Botan::BER_Decoder::decode ( ASN1_Object & obj,
ASN1_Type type_tag = ASN1_Type::NoObject,
ASN1_Class class_tag = ASN1_Class::NoObject )

Definition at line 370 of file ber_dec.cpp.

370 {
371 obj.decode_from(*this);
372 return (*this);
373}

References Botan::ASN1_Object::decode_from().

◆ decode() [2/10]

BER_Decoder & Botan::BER_Decoder::decode ( BigInt & out)
inline

Definition at line 196 of file ber_dec.h.

References decode().

Referenced by decode().

◆ decode() [3/10]

BER_Decoder & Botan::BER_Decoder::decode ( BigInt & v,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )

Definition at line 458 of file ber_dec.cpp.

458 {
459 BER_Object obj = get_next_object();
460 obj.assert_is_a(type_tag, class_tag);
461
462 if(obj.length() == 0) {
463 out.clear();
464 } else {
465 const bool negative = (obj.bits()[0] & 0x80) ? true : false;
466
467 if(negative) {
468 secure_vector<uint8_t> vec(obj.bits(), obj.bits() + obj.length());
469 for(size_t i = obj.length(); i > 0; --i) {
470 if(vec[i - 1]--) {
471 break;
472 }
473 }
474 for(size_t i = 0; i != obj.length(); ++i) {
475 vec[i] = ~vec[i];
476 }
477 out._assign_from_bytes(vec);
478 out.flip_sign();
479 } else {
480 out._assign_from_bytes(obj.data());
481 }
482 }
483
484 return (*this);
485}
BER_Object get_next_object()
Definition ber_dec.cpp:245
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

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

◆ decode() [4/10]

◆ decode() [5/10]

BER_Decoder & Botan::BER_Decoder::decode ( bool & v,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )

Definition at line 397 of file ber_dec.cpp.

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

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

◆ decode() [6/10]

BER_Decoder & Botan::BER_Decoder::decode ( secure_vector< uint8_t > & v,
ASN1_Type real_type,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )

Definition at line 520 of file ber_dec.cpp.

523 {
524 if(real_type != ASN1_Type::OctetString && real_type != ASN1_Type::BitString) {
525 throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", static_cast<uint32_t>(real_type));
526 }
527
528 asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
529 return (*this);
530}

References Botan::BitString, get_next_object(), and Botan::OctetString.

◆ decode() [7/10]

BER_Decoder & Botan::BER_Decoder::decode ( size_t & out)
inline

Definition at line 191 of file ber_dec.h.

References decode().

Referenced by decode().

◆ decode() [8/10]

BER_Decoder & Botan::BER_Decoder::decode ( size_t & v,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )

Definition at line 412 of file ber_dec.cpp.

412 {
413 BigInt integer;
414 decode(integer, type_tag, class_tag);
415
416 if(integer.is_negative()) {
417 throw BER_Decoding_Error("Decoded small integer value was negative");
418 }
419
420 if(integer.bits() > 32) {
421 throw BER_Decoding_Error("Decoded integer value larger than expected");
422 }
423
424 out = 0;
425 for(size_t i = 0; i != 4; ++i) {
426 out = (out << 8) | integer.byte_at(3 - i);
427 }
428
429 return (*this);
430}

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

◆ decode() [9/10]

BER_Decoder & Botan::BER_Decoder::decode ( std::vector< uint8_t > & v,
ASN1_Type real_type,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )

Definition at line 532 of file ber_dec.cpp.

535 {
536 if(real_type != ASN1_Type::OctetString && real_type != ASN1_Type::BitString) {
537 throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", static_cast<uint32_t>(real_type));
538 }
539
540 asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
541 return (*this);
542}

References Botan::BitString, get_next_object(), and Botan::OctetString.

◆ decode() [10/10]

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

Definition at line 208 of file ber_dec.h.

208 {
209 return decode(out, real_type, real_type, ASN1_Class::Universal);
210 }

◆ decode_and_check()

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

Definition at line 272 of file ber_dec.h.

272 {
273 T actual;
274 decode(actual);
275
276 if(actual != expected) {
277 throw Decoding_Error(error_msg);
278 }
279
280 return (*this);
281 }
FE_25519 T
Definition ge.cpp:34

References T.

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

◆ decode_constrained_integer()

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

Definition at line 435 of file ber_dec.cpp.

435 {
436 if(T_bytes > 8) {
437 throw BER_Decoding_Error("Can't decode small integer over 8 bytes");
438 }
439
440 BigInt integer;
441 decode(integer, type_tag, class_tag);
442
443 if(integer.bits() > 8 * T_bytes) {
444 throw BER_Decoding_Error("Decoded integer value larger than expected");
445 }
446
447 uint64_t out = 0;
448 for(size_t i = 0; i != 8; ++i) {
449 out = (out << 8) | integer.byte_at(7 - i);
450 }
451
452 return out;
453}

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

◆ decode_integer_type() [1/2]

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

Definition at line 240 of file ber_dec.h.

240 {
242 }
BER_Decoder & decode_integer_type(T &out)
Definition ber_dec.h:240

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

◆ decode_integer_type() [2/2]

template<typename T >
BER_Decoder & Botan::BER_Decoder::decode_integer_type ( T & out,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )
inline

Definition at line 245 of file ber_dec.h.

245 {
246 out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out)));
247 return (*this);
248 }
uint64_t decode_constrained_integer(ASN1_Type type_tag, ASN1_Class class_tag, size_t T_bytes)
Definition ber_dec.cpp:435

References T.

◆ decode_list()

template<typename T >
BER_Decoder & Botan::BER_Decoder::decode_list ( std::vector< T > & out,
ASN1_Type type_tag = ASN1_Type::Sequence,
ASN1_Class class_tag = ASN1_Class::Universal )

Definition at line 379 of file ber_dec.h.

379 {
380 BER_Decoder list = start_cons(type_tag, class_tag);
381
382 while(list.more_items()) {
383 T value;
384 list.decode(value);
385 vec.push_back(std::move(value));
386 }
387
388 list.end_cons();
389
390 return (*this);
391}
BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag)
Definition ber_dec.cpp:300

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

Referenced by decode_optional_list(), Botan::OCSP::Response::Response(), and Botan::TLS::Session::Session().

◆ decode_null()

BER_Decoder & Botan::BER_Decoder::decode_null ( )

Definition at line 378 of file ber_dec.cpp.

378 {
379 BER_Object obj = get_next_object();
380 obj.assert_is_a(ASN1_Type::Null, ASN1_Class::Universal);
381 if(obj.length() > 0) {
382 throw BER_Decoding_Error("NULL object had nonzero size");
383 }
384 return (*this);
385}

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

◆ decode_octet_string_bigint()

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

Decode an integer value which is typed as an octet string

Definition at line 387 of file ber_dec.cpp.

387 {
390 out = BigInt::from_bytes(out_vec);
391 return (*this);
392}
static BigInt from_bytes(std::span< const uint8_t > bytes)
Definition bigint.cpp:95

References decode(), Botan::BigInt::from_bytes(), and Botan::OctetString.

◆ decode_optional()

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

Definition at line 332 of file ber_dec.h.

332 {
333 BER_Object obj = get_next_object();
334
335 if(obj.is_a(type_tag, class_tag)) {
336 if(class_tag == ASN1_Class::ExplicitContextSpecific) {
337 BER_Decoder(std::move(obj)).decode(out).verify_end();
338 } else {
339 push_back(std::move(obj));
340 decode(out, type_tag, class_tag);
341 }
342 } else {
343 out = default_value;
344 push_back(std::move(obj));
345 }
346
347 return (*this);
348}
void push_back(const BER_Object &obj)
Definition ber_dec.cpp:286

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

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

◆ decode_optional_implicit()

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

Definition at line 354 of file ber_dec.h.

359 {
360 BER_Object obj = get_next_object();
361
362 if(obj.is_a(type_tag, class_tag)) {
363 obj.set_tagging(real_type, real_class);
364 push_back(std::move(obj));
365 decode(out, real_type, real_class);
366 } else {
367 // Not what we wanted, push it back on the stream
368 out = default_value;
369 push_back(std::move(obj));
370 }
371
372 return (*this);
373}

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

◆ decode_optional_list()

template<typename T >
bool Botan::BER_Decoder::decode_optional_list ( std::vector< T > & out,
ASN1_Type type_tag = ASN1_Type::Sequence,
ASN1_Class class_tag = ASN1_Class::Universal )

Definition at line 397 of file ber_dec.h.

397 {
398 if(peek_next_object().is_a(type_tag, class_tag)) {
399 decode_list(vec, type_tag, class_tag);
400 return true;
401 }
402
403 return false;
404}
const BER_Object & peek_next_object()
Definition ber_dec.cpp:234
BER_Decoder & decode_list(std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
Definition ber_dec.h:379

References decode_list(), and peek_next_object().

◆ decode_optional_string() [1/2]

template<typename Alloc >
BER_Decoder & Botan::BER_Decoder::decode_optional_string ( std::vector< uint8_t, Alloc > & out,
ASN1_Type real_type,
ASN1_Type expected_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )
inline

Definition at line 311 of file ber_dec.h.

314 {
315 return decode_optional_string(out, real_type, static_cast<uint32_t>(expected_tag), class_tag);
316 }
BER_Decoder & decode_optional_string(std::vector< uint8_t, Alloc > &out, ASN1_Type real_type, uint32_t expected_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
Definition ber_dec.h:287

◆ decode_optional_string() [2/2]

template<typename Alloc >
BER_Decoder & Botan::BER_Decoder::decode_optional_string ( std::vector< uint8_t, Alloc > & out,
ASN1_Type real_type,
uint32_t expected_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )
inline

Definition at line 287 of file ber_dec.h.

290 {
291 BER_Object obj = get_next_object();
292
293 ASN1_Type type_tag = static_cast<ASN1_Type>(expected_tag);
294
295 if(obj.is_a(type_tag, class_tag)) {
296 if(class_tag == ASN1_Class::ExplicitContextSpecific) {
297 BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
298 } else {
299 push_back(std::move(obj));
300 decode(out, real_type, type_tag, class_tag);
301 }
302 } else {
303 out.clear();
304 push_back(std::move(obj));
305 }
306
307 return (*this);
308 }
ASN1_Type
Definition asn1_obj.h:44

References decode(), Botan::BER_Object::is_a(), and verify_end().

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

◆ discard_remaining()

BER_Decoder & Botan::BER_Decoder::discard_remaining ( )

Discard any data that remains unread Returns (*this)

Definition at line 228 of file ber_dec.cpp.

228 {
229 uint8_t buf;
230 while(m_source->read_byte(buf)) {}
231 return (*this);
232}
size_t read_byte(uint8_t &out)
Definition data_src.cpp:26

References Botan::DataSource::read_byte().

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

◆ end_cons()

BER_Decoder & Botan::BER_Decoder::end_cons ( )

◆ get_next()

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

Definition at line 69 of file ber_dec.h.

69 {
70 ber = get_next_object();
71 return (*this);
72 }

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

◆ get_next_object()

BER_Object Botan::BER_Decoder::get_next_object ( )

Get the next object in the data stream. If EOF, returns an object with type NO_OBJECT.

Definition at line 245 of file ber_dec.cpp.

245 {
246 BER_Object next;
247
248 if(m_pushed.is_set()) {
249 std::swap(next, m_pushed);
250 return next;
251 }
252
253 for(;;) {
254 ASN1_Type type_tag;
255 ASN1_Class class_tag;
256 decode_tag(m_source, type_tag, class_tag);
257 next.set_tagging(type_tag, class_tag);
258 if(next.is_set() == false) { // no more objects
259 return next;
260 }
261
262 size_t field_size;
263 const size_t length = decode_length(m_source, field_size, ALLOWED_EOC_NESTINGS);
264 if(!m_source->check_available(length)) {
265 throw BER_Decoding_Error("Value truncated");
266 }
267
268 uint8_t* out = next.mutable_bits(length);
269 if(m_source->read(out, length) != length) {
270 throw BER_Decoding_Error("Value truncated");
271 }
272
273 if(next.tagging() == static_cast<uint32_t>(ASN1_Type::Eoc)) {
274 continue;
275 } else {
276 break;
277 }
278 }
279
280 return next;
281}
bool is_set() const
Definition asn1_obj.h:139
virtual size_t read(uint8_t out[], size_t length)=0
virtual bool check_available(size_t n)=0
ASN1_Class
Definition asn1_obj.h:29

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

Referenced by decode(), decode(), decode(), decode(), Botan::AlternativeName::decode_from(), Botan::ASN1_String::decode_from(), Botan::ASN1_Time::decode_from(), Botan::Cert_Extension::TNAuthList::Entry::decode_from(), Botan::GeneralName::decode_from(), Botan::OID::decode_from(), decode_null(), decode_optional(), decode_optional_implicit(), peek_next_object(), and start_cons().

◆ get_next_octet_string()

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

Definition at line 198 of file ber_dec.h.

198 {
199 std::vector<uint8_t> out_vec;
201 return out_vec;
202 }

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

◆ get_next_value()

template<typename T >
requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
BER_Decoder & Botan::BER_Decoder::get_next_value ( T & out,
ASN1_Type type_tag,
ASN1_Class class_tag = ASN1_Class::ContextSpecific )
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_Type enum to assert type on object read
class_tagASN1_Type enum to assert class on object read (default: CONTEXT_SPECIFIC)
Returns
this reference

Definition at line 152 of file ber_dec.h.

154 {
155 BER_Object obj = get_next_object();
156 obj.assert_is_a(type_tag, class_tag);
157
158 if(obj.length() != sizeof(T)) {
159 throw BER_Decoding_Error("Size mismatch. Object value size is " + std::to_string(obj.length()) +
160 "; Output type size is " + std::to_string(sizeof(T)));
161 }
162
163 copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length());
164
165 return (*this);
166 }
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146

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

◆ more_items()

bool Botan::BER_Decoder::more_items ( ) const

Return true if there is at least one more item remaining

Definition at line 201 of file ber_dec.cpp.

201 {
202 if(m_source->end_of_data() && !m_pushed.is_set()) {
203 return false;
204 }
205 return true;
206}

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

Referenced by Botan::AlternativeName::decode_from(), Botan::Cert_Extension::TNAuthList::Entry::decode_from(), Botan::CRL_Entry::decode_from(), Botan::Extensions::decode_from(), Botan::X509_DN::decode_from(), decode_list(), and Botan::OCSP::Response::Response().

◆ operator=()

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

◆ peek_next_object()

const BER_Object & Botan::BER_Decoder::peek_next_object ( )

Peek at the next object without removing it from the stream

If an object has been pushed, then it returns that object. Otherwise it reads the next object and pushes it. Thus, a you call peek_next_object followed by push_back without a subsequent read, it will fail.

Definition at line 234 of file ber_dec.cpp.

234 {
235 if(!m_pushed.is_set()) {
236 m_pushed = get_next_object();
237 }
238
239 return m_pushed;
240}

References get_next_object(), and Botan::BER_Object::is_set().

Referenced by decode_optional_list().

◆ push_back() [1/2]

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

Push an object back onto the stream. Throws if another object was previously pushed and has not been subsequently read out.

Definition at line 293 of file ber_dec.cpp.

293 {
294 if(m_pushed.is_set()) {
295 throw Invalid_State("BER_Decoder: Only one push back is allowed");
296 }
297 m_pushed = std::move(obj);
298}

References Botan::BER_Object::is_set().

◆ push_back() [2/2]

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

Push an object back onto the stream. Throws if another object was previously pushed and has not been subsequently read out.

Definition at line 286 of file ber_dec.cpp.

286 {
287 if(m_pushed.is_set()) {
288 throw Invalid_State("BER_Decoder: Only one push back is allowed");
289 }
290 m_pushed = obj;
291}

References Botan::BER_Object::is_set().

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

◆ raw_bytes()

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

Definition at line 172 of file ber_dec.h.

172 {
173 out.clear();
174 uint8_t buf;
175 while(m_source->read_byte(buf)) {
176 out.push_back(buf);
177 }
178 return (*this);
179 }

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

◆ start_cons()

BER_Decoder Botan::BER_Decoder::start_cons ( ASN1_Type type_tag,
ASN1_Class class_tag )

Definition at line 300 of file ber_dec.cpp.

300 {
301 BER_Object obj = get_next_object();
302 obj.assert_is_a(type_tag, class_tag | ASN1_Class::Constructed);
303 return BER_Decoder(std::move(obj), this);
304}

References Botan::BER_Object::assert_is_a(), BER_Decoder(), Botan::Constructed, and get_next_object().

Referenced by decode_list().

◆ start_context_specific()

BER_Decoder Botan::BER_Decoder::start_context_specific ( uint32_t tag)
inline

◆ start_explicit_context_specific()

BER_Decoder Botan::BER_Decoder::start_explicit_context_specific ( uint32_t tag)
inline

Definition at line 131 of file ber_dec.h.

◆ start_sequence()

◆ start_set()

BER_Decoder Botan::BER_Decoder::start_set ( )
inline

◆ verify_end() [1/2]

BER_Decoder & Botan::BER_Decoder::verify_end ( )

Verify the stream is concluded, throws otherwise. Returns (*this)

Definition at line 211 of file ber_dec.cpp.

211 {
212 return verify_end("BER_Decoder::verify_end called, but data remains");
213}
BER_Decoder & verify_end()
Definition ber_dec.cpp:211

References verify_end().

Referenced by Botan::AlternativeName::decode_from(), Botan::Extensions::decode_from(), decode_optional_string(), Botan::Ed448_PrivateKey::Ed448_PrivateKey(), Botan::pbes2_decrypt(), and verify_end().

◆ verify_end() [2/2]

BER_Decoder & Botan::BER_Decoder::verify_end ( std::string_view err_msg)

Verify the stream is concluded, throws otherwise. Returns (*this)

Definition at line 218 of file ber_dec.cpp.

218 {
219 if(!m_source->end_of_data() || m_pushed.is_set()) {
220 throw Decoding_Error(err);
221 }
222 return (*this);
223}

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


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