8#ifndef BOTAN_BER_DECODER_H_
9#define BOTAN_BER_DECODER_H_
11#include <botan/asn1_obj.h>
12#include <botan/data_src.h>
42 explicit BER_Decoder(
const std::vector<uint8_t>& vec);
103 bool more_items()
const;
153 template <
typename T>
155 requires std::is_standard_layout_v<T> && std::is_trivial_v<T>
160 if(obj.
length() !=
sizeof(T)) {
162 "; Output type size is " + std::to_string(
sizeof(T)));
165 std::memcpy(
reinterpret_cast<uint8_t*
>(&out), obj.
bits(), obj.
length());
173 template <
typename Alloc>
177 while(m_source->read_byte(buf)) {
201 std::vector<uint8_t> out_vec;
209 template <
typename Alloc>
239 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
ASN1_Class class_tag,
size_t T_bytes);
241 template <
typename T>
246 template <
typename T>
252 template <
typename T>
254 std::optional<T> optval;
256 out = optval ? *optval : default_value;
260 template <
typename T>
263 template <
typename T>
269 const T& default_value = T());
271 template <
typename T>
276 template <
typename T>
277 bool decode_optional_list(std::vector<T>& out,
281 template <
typename T>
286 if(actual != expected) {
296 template <
typename Alloc>
299 uint32_t expected_tag,
305 if(obj.
is_a(type_tag, class_tag)) {
307 BER_Decoder(std::move(obj)).decode(out, real_type).verify_end();
310 decode(out, real_type, type_tag, class_tag);
320 template <
typename Alloc>
337 mutable std::unique_ptr<DataSource> m_data_src;
347 if(obj.
is_a(type_tag, class_tag)) {
350 BER_Decoder(std::move(obj)).decode(out).verify_end();
353 this->
decode(out, type_tag, class_tag);
355 optval = std::move(out);
358 optval = std::nullopt;
373 const T& default_value) {
376 if(obj.
is_a(type_tag, class_tag)) {
377 obj.set_tagging(real_type, real_class);
379 decode(out, real_type, real_class);
#define BOTAN_PUBLIC_API(maj, min)
#define BOTAN_FUTURE_EXPLICIT
BOTAN_FUTURE_EXPLICIT BER_Decoder(BER_Object &&obj)
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 & get_next_value(T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
BER_Decoder & decode(bool &out)
uint64_t decode_constrained_integer(ASN1_Type type_tag, ASN1_Class class_tag, size_t T_bytes)
BOTAN_FUTURE_EXPLICIT BER_Decoder(const BER_Object &obj)
BER_Decoder & decode(BigInt &out)
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 & operator=(BER_Decoder &&)=default
BER_Decoder start_cons(ASN1_Type type_tag, ASN1_Class class_tag)
BER_Decoder(BER_Decoder &&other)=default
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)
BOTAN_FUTURE_EXPLICIT BER_Decoder(std::span< const uint8_t > buf)
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