8#ifndef BOTAN_BER_DECODER_H_
9#define BOTAN_BER_DECODER_H_
11#include <botan/asn1_obj.h>
12#include <botan/data_src.h>
41 explicit BER_Decoder(
const std::vector<uint8_t>& vec);
100 bool more_items()
const;
150 template <
typename T>
152 requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
157 if(obj.
length() !=
sizeof(T)) {
159 "; Output type size is " + std::to_string(
sizeof(T)));
162 std::memcpy(
reinterpret_cast<uint8_t*
>(&out), obj.
bits(), obj.
length());
170 template <
typename Alloc>
174 while(m_source->read_byte(buf)) {
198 std::vector<uint8_t> out_vec;
206 template <
typename Alloc>
236 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
ASN1_Class class_tag,
size_t T_bytes);
238 template <
typename T>
243 template <
typename T>
249 template <
typename T>
252 template <
typename T>
258 const T& default_value = T());
260 template <
typename T>
265 template <
typename T>
266 bool decode_optional_list(std::vector<T>& out,
270 template <
typename T>
275 if(actual != expected) {
285 template <
typename Alloc>
288 uint32_t expected_tag,
294 if(obj.
is_a(type_tag, class_tag)) {
296 BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
299 decode(out, real_type, type_tag, class_tag);
309 template <
typename Alloc>
324 mutable std::unique_ptr<DataSource> m_data_src;
334 if(obj.
is_a(type_tag, class_tag)) {
336 BER_Decoder(std::move(obj)).decode(out).verify_end();
339 decode(out, type_tag, class_tag);
358 const T& default_value) {
361 if(obj.
is_a(type_tag, class_tag)) {
362 obj.set_tagging(real_type, real_class);
364 decode(out, real_type, real_class);
#define BOTAN_PUBLIC_API(maj, min)
BER_Decoder & get_next_value(T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
BER_Decoder(const uint8_t buf[], size_t len)
const BER_Object & peek_next_object()
void push_back(const BER_Object &obj)
BER_Object get_next_object()
BER_Decoder & decode(bool &out)
uint64_t decode_constrained_integer(ASN1_Type type_tag, ASN1_Class class_tag, size_t T_bytes)
BER_Decoder & decode(BigInt &out)
BER_Decoder(BER_Object &&obj)
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 & decode(std::vector< uint8_t, Alloc > &out, ASN1_Type real_type)
BER_Decoder start_explicit_context_specific(uint32_t tag)
BER_Decoder(std::span< const uint8_t > buf)
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_and_check(const T &expected, std::string_view error_msg)
bool decode_optional_list(std::vector< T > &out, ASN1_Type type_tag=ASN1_Type::Sequence, ASN1_Class class_tag=ASN1_Class::Universal)
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
bool is_a(ASN1_Type type_tag, ASN1_Class class_tag) const
void assert_is_a(ASN1_Type type_tag, ASN1_Class class_tag, std::string_view descr="object") const
@ ExplicitContextSpecific
std::vector< T, secure_allocator< T > > secure_vector