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);
147 template <
typename T>
152 static_assert(std::is_standard_layout<T>::value && std::is_trivial<T>::value,
"Type must be POD");
159 "Size mismatch. Object value size is " +
161 "; Output type size is " +
172 template<
typename Alloc>
177 while(m_source->read_byte(buf))
210 std::vector<uint8_t> out_vec;
218 template<
typename Alloc>
255 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
269 out =
static_cast<T>(decode_constrained_integer(type_tag, class_tag,
sizeof(out)));
277 const T& default_value =
T());
286 const T& default_value =
T());
295 const std::string& error_msg)
300 if(actual != expected)
309 template<
typename Alloc>
312 uint32_t expected_tag,
319 if(obj.
is_a(type_tag, class_tag))
327 push_back(std::move(obj));
328 decode(out, real_type, type_tag, class_tag);
334 push_back(std::move(obj));
340 template<
typename Alloc>
346 return decode_optional_string(out, real_type,
347 static_cast<uint32_t
>(expected_tag),
358 mutable std::unique_ptr<DataSource> m_data_src;
368 const T& default_value)
372 if(obj.
is_a(type_tag, class_tag))
376 BER_Decoder(std::move(obj)).decode(out).verify_end();
381 decode(out, type_tag, class_tag);
403 const T& default_value)
407 if(obj.
is_a(type_tag, class_tag))
409 obj.set_tagging(real_type, real_class);
411 decode(out, real_type, real_class);
BER_Decoder(const uint8_t buf[], size_t len)
void push_back(const BER_Object &obj)
BER_Decoder & get_next_value(T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
BER_Object get_next_object()
BER_Decoder & decode(bool &out)
BER_Decoder & decode(BigInt &out)
BER_Decoder(BER_Object &&obj)
BER_Decoder & decode_and_check(const T &expected, const std::string &error_msg)
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)
BER_Decoder & raw_bytes(std::vector< uint8_t, Alloc > &out)
BER_Decoder & decode_integer_type(T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
std::vector< uint8_t > get_next_octet_string()
BER_Decoder & verify_end()
BER_Decoder & decode(std::vector< uint8_t, Alloc > &out, ASN1_Type real_type)
BER_Decoder start_explicit_context_specific(uint32_t tag)
BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag)
BER_Decoder(const BER_Object &obj)
BER_Decoder & decode_list(std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
BER_Decoder start_sequence()
BER_Decoder start_context_specific(uint32_t tag)
BER_Decoder & decode_optional(T &out, ASN1_Type type_tag, ASN1_Class class_tag, const T &default_value=T())
BER_Decoder & decode(size_t &out)
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)
BER_Decoder & decode_integer_type(T &out)
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())
BER_Decoder & operator=(const BER_Decoder &)=delete
BER_Decoder & get_next(BER_Object &ber)
const uint8_t * bits() const
void assert_is_a(ASN1_Type type_tag, ASN1_Class class_tag, const std::string &descr="object") const
bool is_a(ASN1_Type type_tag, ASN1_Class class_tag) 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)
@ ExplicitContextSpecific
constexpr void copy_mem(T *out, const T *in, size_t n)
std::vector< T, secure_allocator< T > > secure_vector