8#ifndef BOTAN_BER_DECODER_H_
9#define BOTAN_BER_DECODER_H_
11#include <botan/asn1_obj.h>
12#include <botan/data_src.h>
37 explicit BER_Decoder(
const std::vector<uint8_t>& vec);
68 ber = get_next_object();
89 bool more_items()
const;
101 BER_Decoder& verify_end(
const std::string& err_msg);
130 template <
typename T>
135 static_assert(std::is_standard_layout<T>::value && std::is_trivial<T>::value,
"Type must be POD");
142 "Size mismatch. Object value size is " +
144 "; Output type size is " +
155 template<
typename Alloc>
160 while(m_source->read_byte(buf))
193 std::vector<uint8_t> out_vec;
201 template<
typename Alloc>
238 uint64_t decode_constrained_integer(
ASN1_Tag type_tag,
252 out =
static_cast<T>(decode_constrained_integer(type_tag, class_tag,
sizeof(out)));
260 const T& default_value =
T());
269 const T& default_value =
T());
278 const std::string& error_msg)
283 if(actual != expected)
292 template<
typename Alloc>
302 if(obj.
is_a(type_tag, class_tag))
310 push_back(std::move(obj));
311 decode(out, real_type, type_tag, class_tag);
317 push_back(std::move(obj));
330 mutable std::unique_ptr<DataSource> m_data_src;
340 const T& default_value)
344 if(obj.
is_a(type_tag, class_tag))
348 BER_Decoder(std::move(obj)).decode(out).verify_end();
353 decode(out, type_tag, class_tag);
375 const T& default_value)
379 if(obj.
is_a(type_tag, class_tag))
381 obj.set_tagging(real_type, real_class);
383 decode(out, real_type, real_class);
BER_Decoder start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
BER_Decoder & decode_list(std::vector< T > &out, ASN1_Tag type_tag=SEQUENCE, ASN1_Tag class_tag=UNIVERSAL)
BER_Decoder(const uint8_t buf[], size_t len)
void push_back(const BER_Object &obj)
BER_Object get_next_object()
BER_Decoder & decode(std::vector< uint8_t, Alloc > &out, ASN1_Tag real_type)
BER_Decoder & get_next_value(T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & decode(bool &out)
BER_Decoder & decode(BigInt &out)
BER_Decoder(BER_Object &&obj)
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 & decode_and_check(const T &expected, const std::string &error_msg)
BER_Decoder & raw_bytes(std::vector< uint8_t, Alloc > &out)
std::vector< uint8_t > get_next_octet_string()
BER_Decoder & decode_optional(T &out, ASN1_Tag type_tag, ASN1_Tag class_tag, const T &default_value=T())
BER_Decoder & verify_end()
BER_Decoder(const BER_Object &obj)
BER_Decoder & decode_integer_type(T &out, ASN1_Tag type_tag, ASN1_Tag class_tag=CONTEXT_SPECIFIC)
BER_Decoder & decode(size_t &out)
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())
BER_Decoder & decode_integer_type(T &out)
BER_Decoder & operator=(const BER_Decoder &)=delete
BER_Decoder & get_next(BER_Object &ber)
const uint8_t * bits() const
bool is_a(ASN1_Tag type_tag, ASN1_Tag class_tag) const
void assert_is_a(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::string &descr="object") const
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
std::string to_string(const BER_Object &obj)
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
void copy_mem(T *out, const T *in, size_t n)
std::vector< T, secure_allocator< T > > secure_vector