Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::BER_Decoder Class Referencefinal

`#include <ber_dec.h>`

## Public Member Functions
| BER_Decoder (const uint8_t buf[], size_t len)
| BER_Decoder (const secure_vector< uint8_t > &vec)
| BER_Decoder (const std::vector< uint8_t > &vec)
| BER_Decoder (DataSource &src)
| BER_Decoder (const BER_Object &obj)
| BER_Decoder (BER_Object &&obj)
| BER_Decoder (const BER_Decoder &other)
BER_Decoder & | decode (bool &out)
BER_Decoder & | decode (size_t &out)
BER_Decoder & | decode (BigInt &out)
template<typename Alloc >
BER_Decoder & | decode (std::vector< uint8_t, Alloc > &out, ASN1_Tag real_type)
BER_Decoder & | decode (bool &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & | decode (size_t &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & | decode (BigInt &v, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & | decode (std::vector< uint8_t > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & | decode (secure_vector< uint8_t > &v, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & | decode (class ASN1_Object &obj, ASN1_Tag type_tag=NO_OBJECT, ASN1_Tag class_tag=NO_OBJECT)
template<typename T >
BER_Decoder & | decode_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_Decoder & | decode_integer_type (T &out)
template<typename T >
BER_Decoder & | decode_integer_type (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
template<typename T >
BER_Decoder & | decode_list (std::vector< T > &out, ASN1_Tag type_tag=SEQUENCE, ASN1_Tag class_tag=UNIVERSAL)
BER_Decoder & | decode_null ()
BER_Decoder & | decode_octet_string_bigint (BigInt &b)
template<typename T >
BER_Decoder & | decode_optional (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag, const T &default_value=T())
template<typename T >
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())
template<typename Alloc >
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)
BER_Decoder & | discard_remaining ()
BER_Decoder & | end_cons ()
BER_Decoder & | get_next (BER_Object &ber)
BER_Object | get_next_object ()
std::vector< uint8_t > | get_next_octet_string ()
template<typename T >
BER_Decoder & | get_next_value (T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
bool | more_items () const
BER_Decoder & | operator= (const BER_Decoder &)=delete
void | push_back (const BER_Object &obj)
void | push_back (BER_Object &&obj)
template<typename Alloc >
BER_Decoder & | raw_bytes (std::vector< uint8_t, Alloc > &out)
BER_Decoder | start_cons (ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
BER_Decoder & | verify_end ()
BER_Decoder & | verify_end (const std::string &err_msg)

## Detailed Description

BER Decoding Object

Definition at line 21 of file ber_dec.h.

## Constructor & Destructor Documentation

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

Referenced by decode_optional(), and start_cons().

328 {
329 m_data_src.reset(new DataSource_Memory(data, length));
330 m_source = m_data_src.get();
331 }

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

Set up to BER decode the data in vec

Definition at line 336 of file ber_dec.cpp.

337 {
338 m_data_src.reset(new DataSource_Memory(data));
339 m_source = m_data_src.get();
340 }

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

Set up to BER decode the data in vec

Definition at line 345 of file ber_dec.cpp.

346 {
347 m_data_src.reset(new DataSource_Memory(data.data(), data.size()));
348 m_source = m_data_src.get();
349 }

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

Set up to BER decode the data in src

Definition at line 319 of file ber_dec.cpp.

320 {
321 m_source = &src;
322 }

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

Set up to BER decode the data in obj

Definition at line 47 of file ber_dec.h.

47 :
48 BER_Decoder(obj.bits(), obj.length()) {}
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327

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

Set up to BER decode the data in obj

Definition at line 53 of file ber_dec.h.

53 :
54 BER_Decoder(std::move(obj), nullptr) {}
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327

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

Definition at line 354 of file ber_dec.cpp.

355 {
356 m_source = other.m_source;
357
358 // take ownership
359 std::swap(m_data_src, other.m_data_src);
360 m_parent = other.m_parent;
361 }

## Member Function Documentation

BER_Decoder& Botan::BER_Decoder::decode | ( | bool & | out | ) |
| inline

Decode a BER encoded BOOLEAN

Definition at line 170 of file ber_dec.h.

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

Referenced by Botan::PK_Verifier::check_signature(), Botan::Curve25519_PrivateKey::Curve25519_PrivateKey(), decode(), decode_constrained_integer(), 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(), decode_list(), decode_octet_string_bigint(), decode_optional(), decode_optional_implicit(), decode_optional_string(), Botan::DL_Scheme_PrivateKey::DL_Scheme_PrivateKey(), Botan::DL_Scheme_PublicKey::DL_Scheme_PublicKey(), Botan::Ed25519_PrivateKey::Ed25519_PrivateKey(), Botan::GOST_3410_PublicKey::GOST_3410_PublicKey(), Botan::X509::load_key(), Botan::McEliece_PrivateKey::McEliece_PrivateKey(), Botan::McEliece_PublicKey::McEliece_PublicKey(), Botan::pbes2_decrypt(), Botan::OCSP::Response::Response(), Botan::RSA_PublicKey::RSA_PublicKey(), and Botan::TLS::Session::Session().

171 {
172 return decode(out, BOOLEAN, UNIVERSAL);
173 }
Botan::BOOLEAN
Definition: asn1_obj.h:33
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::UNIVERSAL
Definition: asn1_obj.h:24

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

Definition at line 178 of file ber_dec.h.

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

179 {
180 return decode(out, INTEGER, UNIVERSAL);
181 }
Botan::INTEGER
Definition: asn1_obj.h:34
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::UNIVERSAL
Definition: asn1_obj.h:24

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

Definition at line 186 of file ber_dec.h.

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

187 {
188 return decode(out, INTEGER, UNIVERSAL);
189 }
Botan::INTEGER
Definition: asn1_obj.h:34
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::UNIVERSAL
Definition: asn1_obj.h:24
template<typename Alloc >

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

Definition at line 202 of file ber_dec.h.

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

203 {
204 return decode(out, real_type, real_type, UNIVERSAL);
205 }
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::UNIVERSAL
Definition: asn1_obj.h:24

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

Definition at line 396 of file ber_dec.cpp.

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

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

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

Definition at line 412 of file ber_dec.cpp.

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

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

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

Definition at line 458 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().

461 {
462 BER_Object obj = get_next_object();
463 obj.assert_is_a(type_tag, class_tag);
464
465 if(obj.length() == 0)
466 {
467 out = 0;
468 }
469 else
470 {
471 const bool negative = (obj.bits()[0] & 0x80) ? true : false;
472
473 if(negative)
474 {
475 secure_vector<uint8_t> vec(obj.bits(), obj.bits() + obj.length());
476 for(size_t i = obj.length(); i > 0; --i)
477 if(vec[i-1]--)
478 break;
479 for(size_t i = 0; i != obj.length(); ++i)
480 vec[i] = ~vec[i];
481 out = BigInt(vec.data(), vec.size());
482 out.flip_sign();
483 }
484 else
485 {
486 out = BigInt(obj.bits(), obj.length());
487 }
488 }
489
490 return (*this);
491 }
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237

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

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

541 {
542 if(real_type != OCTET_STRING && real_type != BIT_STRING)
543 throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
544
545 asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
546 return (*this);
547 }
Botan::OCTET_STRING
Definition: asn1_obj.h:36
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
Botan::BIT_STRING
Definition: asn1_obj.h:35

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

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

530 {
531 if(real_type != OCTET_STRING && real_type != BIT_STRING)
532 throw BER_Bad_Tag("Bad tag for {BIT,OCTET} STRING", real_type);
533
534 asn1_decode_binary_string(buffer, get_next_object(), real_type, type_tag, class_tag);
535 return (*this);
536 }
Botan::OCTET_STRING
Definition: asn1_obj.h:36
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
Botan::BIT_STRING
Definition: asn1_obj.h:35

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

References Botan::ASN1_Object::decode_from().

368 {
369 obj.decode_from(*this);
370 return (*this);
371 }
template<typename T >

BER_Decoder& Botan::BER_Decoder::decode_and_check | ( | const T & | expected,
|  | const std::string & | error_msg
| ) |  |
| inline

Definition at line 277 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().

279 {
280 T actual;
281 decode(actual);
282
283 if(actual != expected)
284 throw Decoding_Error(error_msg);
285
286 return (*this);
287 }
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
T
fe T
Definition: ge.cpp:37

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

Definition at line 435 of file ber_dec.cpp.

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

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

BER_Decoder& Botan::BER_Decoder::decode_integer_type | ( | T & | out | ) |
| inline

Definition at line 242 of file ber_dec.h.

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

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

243 {
244 return decode_integer_type<T>(out, INTEGER, UNIVERSAL);
245 }
Botan::INTEGER
Definition: asn1_obj.h:34
Botan::UNIVERSAL
Definition: asn1_obj.h:24
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 248 of file ber_dec.h.

References T.

251 {
252 out = static_cast<T>(decode_constrained_integer(type_tag, class_tag, sizeof(out)));
253 return (*this);
254 }
Botan::BER_Decoder::decode_constrained_integer
uint64_t decode_constrained_integer(ASN1_Tag type_tag, ASN1_Tag class_tag, size_t T_bytes)
Definition: ber_dec.cpp:435
T
fe T
Definition: ge.cpp:37
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 398 of file ber_dec.h.

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

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

401 {
402 BER_Decoder list = start_cons(type_tag, class_tag);
403
404 while(list.more_items())
405 {
406 T value;
407 list.decode(value);
408 vec.push_back(std::move(value));
409 }
410
411 list.end_cons();
412
413 return (*this);
414 }
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327
Botan::BER_Decoder::start_cons
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Definition: ber_dec.cpp:290
T
fe T
Definition: ge.cpp:37

BER_Decoder & Botan::BER_Decoder::decode_null | ( |  | ) |

Definition at line 376 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.

377 {
378 BER_Object obj = get_next_object();
379 obj.assert_is_a(NULL_TAG, UNIVERSAL);
380 if(obj.length() > 0)
381 throw BER_Decoding_Error("NULL object had nonzero size");
382 return (*this);
383 }
Botan::UNIVERSAL
Definition: asn1_obj.h:24
Botan::NULL_TAG
Definition: asn1_obj.h:37
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237

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

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

386 {
387 secure_vector<uint8_t> out_vec;
388 decode(out_vec, OCTET_STRING);
389 out = BigInt::decode(out_vec.data(), out_vec.size());
390 return (*this);
391 }
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::OCTET_STRING
Definition: asn1_obj.h:36
Botan::BigInt::decode
static BigInt decode(const uint8_t buf[], size_t length)
Definition: bigint.h:798
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 337 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(), and Botan::OCSP::Response::Response().

341 {
342 BER_Object obj = get_next_object();
343
344 if(obj.is_a(type_tag, class_tag))
345 {
346 if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
347 {
348 BER_Decoder(std::move(obj)).decode(out).verify_end();
349 }
350 else
351 {
352 push_back(std::move(obj));
353 decode(out, type_tag, class_tag);
354 }
355 }
356 else
357 {
358 out = default_value;
359 push_back(std::move(obj));
360 }
361
362 return (*this);
363 }
Botan::CONSTRUCTED
Definition: asn1_obj.h:28
Botan::BER_Decoder::push_back
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:276
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
Botan::CONTEXT_SPECIFIC
Definition: asn1_obj.h:26
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 369 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().

376 {
377 BER_Object obj = get_next_object();
378
379 if(obj.is_a(type_tag, class_tag))
380 {
381 obj.set_tagging(real_type, real_class);
382 push_back(std::move(obj));
383 decode(out, real_type, real_class);
384 }
385 else
386 {
387 // Not what we wanted, push it back on the stream
388 out = default_value;
389 push_back(std::move(obj));
390 }
391
392 return (*this);
393 }
Botan::BER_Decoder::push_back
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:276
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
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 293 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().

297 {
298 BER_Object obj = get_next_object();
299
300 ASN1_Tag type_tag = static_cast<ASN1_Tag>(type_no);
301
302 if(obj.is_a(type_tag, class_tag))
303 {
304 if((class_tag & CONSTRUCTED) && (class_tag & CONTEXT_SPECIFIC))
305 {
306 BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
307 }
308 else
309 {
310 push_back(std::move(obj));
311 decode(out, real_type, type_tag, class_tag);
312 }
313 }
314 else
315 {
316 out.clear();
317 push_back(std::move(obj));
318 }
319
320 return (*this);
321 }
Botan::CONSTRUCTED
Definition: asn1_obj.h:28
Botan::BER_Decoder::push_back
void push_back(const BER_Object &obj)
Definition: ber_dec.cpp:276
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:23
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
Botan::CONTEXT_SPECIFIC
Definition: asn1_obj.h:26

BER_Decoder & Botan::BER_Decoder::discard_remaining | ( |  | ) |

Discard any data that remains unread Returns (*this)

Definition at line 226 of file ber_dec.cpp.

References Botan::DataSource::read_byte().

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

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

BER_Decoder & Botan::BER_Decoder::end_cons | ( |  | ) |

Finish decoding a constructed data, throws if any data remains. Returns the parent of *this (ie the object on which start_cons was called).

Definition at line 300 of file ber_dec.cpp.

References Botan::DataSource::end_of_data().

Referenced by Botan::Attribute::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_PublicKey::RSA_PublicKey(), and Botan::TLS::Session::Session().

301 {
302 if(!m_parent)
303 throw Invalid_State("BER_Decoder::end_cons called with null parent");
304 if(!m_source->end_of_data())
305 throw Decoding_Error("BER_Decoder::end_cons called with data left");
306 return (*m_parent);
307 }
Botan::DataSource::end_of_data
virtual bool end_of_data() const =0

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

Definition at line 66 of file ber_dec.h.

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

67 {
68 ber = get_next_object();
69 return (*this);
70 }
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237

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 237 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::AlternativeName::decode_from(), Botan::X509_Time::decode_from(), Botan::OID::decode_from(), Botan::GeneralName::decode_from(), decode_null(), decode_optional(), decode_optional_implicit(), and start_cons().

238 {
239 BER_Object next;
240
241 if(m_pushed.is_set())
242 {
243 std::swap(next, m_pushed);
244 return next;
245 }
246
247 for(;;)
248 {
249 ASN1_Tag type_tag, class_tag;
250 decode_tag(m_source, type_tag, class_tag);
251 next.set_tagging(type_tag, class_tag);
252 if(next.is_set() == false) // no more objects
253 return next;
254
255 size_t field_size;
256 const size_t length = decode_length(m_source, field_size, ALLOWED_EOC_NESTINGS);
257 if(!m_source->check_available(length))
258 throw BER_Decoding_Error("Value truncated");
259
260 uint8_t* out = next.mutable_bits(length);
261 if(m_source->read(out, length) != length)
262 throw BER_Decoding_Error("Value truncated");
263
264 if(next.tagging() == EOC)
265 continue;
266 else
267 break;
268 }
269
270 return next;
271 }
Botan::DataSource::check_available
virtual bool check_available(size_t n)=0
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:23
Botan::DataSource::read
virtual size_t read(uint8_t out[], size_t length) BOTAN_WARN_UNUSED_RESULT=0
Botan::EOC
Definition: asn1_obj.h:32
Botan::BER_Object::is_set
bool is_set() const
Definition: asn1_obj.h:110

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

Definition at line 191 of file ber_dec.h.

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

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

192 {
193 std::vector<uint8_t> out_vec;
194 decode(out_vec, OCTET_STRING);
195 return out_vec;
196 }
Botan::BER_Decoder::decode
BER_Decoder & decode(bool &out)
Definition: ber_dec.h:170
Botan::OCTET_STRING
Definition: asn1_obj.h:36
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

  out | POD type reference where to copy object value
  type_tag | ASN1_Tag enum to assert type on object read
  class_tag | ASN1_Tag enum to assert class on object read (default: CONTEXT_SPECIFIC)

Returns
  this reference

Definition at line 131 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().

134 {
135 static_assert(std::is_pod<T>::value, "Type must be POD");
136
137 BER_Object obj = get_next_object();
138 obj.assert_is_a(type_tag, class_tag);
139
140 if (obj.length() != sizeof(T))
141 throw BER_Decoding_Error(
142 "Size mismatch. Object value size is " +
143 std::to_string(obj.length()) +
144 "; Output type size is " +
145 std::to_string(sizeof(T)));
146
147 copy_mem(reinterpret_cast<uint8_t*>(&out), obj.bits(), obj.length());
148
149 return (*this);
150 }
Botan::ASN1::to_string
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213
Botan::copy_mem
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:132
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237
T
fe T
Definition: ge.cpp:37

bool Botan::BER_Decoder::more_items | ( |  | ) | const

Return true if there is at least one more item remaining

Definition at line 198 of file ber_dec.cpp.

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

Referenced by Botan::PK_Verifier::check_signature(), Botan::AlternativeName::decode_from(), Botan::X509_DN::decode_from(), Botan::CRL_Entry::decode_from(), Botan::Extensions::decode_from(), decode_list(), and Botan::OCSP::Response::Response().

199 {
200 if(m_source->end_of_data() && !m_pushed.is_set())
201 return false;
202 return true;
203 }
Botan::DataSource::end_of_data
virtual bool end_of_data() const =0
Botan::BER_Object::is_set
bool is_set() const
Definition: asn1_obj.h:110

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

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

277 {
278 if(m_pushed.is_set())
279 throw Invalid_State("BER_Decoder: Only one push back is allowed");
280 m_pushed = obj;
281 }
Botan::BER_Object::is_set
bool is_set() const
Definition: asn1_obj.h:110

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

References Botan::BER_Object::is_set().

284 {
285 if(m_pushed.is_set())
286 throw Invalid_State("BER_Decoder: Only one push back is allowed");
287 m_pushed = std::move(obj);
288 }
Botan::BER_Object::is_set
bool is_set() const
Definition: asn1_obj.h:110
template<typename Alloc >

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

Definition at line 156 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().

157 {
158 out.clear();
159 uint8_t buf;
160 while(m_source->read_byte(buf))
161 out.push_back(buf);
162 return (*this);
163 }
Botan::DataSource::read_byte
size_t read_byte(uint8_t &out)
Definition: data_src.cpp:23

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

Start decoding a constructed data (sequence or set)

Definition at line 290 of file ber_dec.cpp.

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

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

291 {
292 BER_Object obj = get_next_object();
293 obj.assert_is_a(type_tag, ASN1_Tag(class_tag | CONSTRUCTED));
294 return BER_Decoder(std::move(obj), this);
295 }
Botan::CONSTRUCTED
Definition: asn1_obj.h:28
Botan::ASN1_Tag
ASN1_Tag
Definition: asn1_obj.h:23
Botan::BER_Decoder::BER_Decoder
BER_Decoder(const uint8_t buf[], size_t len)
Definition: ber_dec.cpp:327
Botan::BER_Decoder::get_next_object
BER_Object get_next_object()
Definition: ber_dec.cpp:237

BER_Decoder & Botan::BER_Decoder::verify_end | ( |  | ) |

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

Definition at line 208 of file ber_dec.cpp.

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

209 {
210 return verify_end("BER_Decoder::verify_end called, but data remains");
211 }
Botan::BER_Decoder::verify_end
BER_Decoder & verify_end()
Definition: ber_dec.cpp:208

BER_Decoder & Botan::BER_Decoder::verify_end | ( | const std::string & | err_msg | ) |

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

Definition at line 216 of file ber_dec.cpp.

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

217 {
218 if(!m_source->end_of_data() || m_pushed.is_set())
219 throw Decoding_Error(err);
220 return (*this);
221 }
Botan::DataSource::end_of_data
virtual bool end_of_data() const =0
Botan::BER_Object::is_set
bool is_set() const
Definition: asn1_obj.h:110

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

- src/lib/asn1/ber_dec.h
- src/lib/asn1/ber_dec.cpp