8#ifndef BOTAN_BER_DECODER_H_
9#define BOTAN_BER_DECODER_H_
11#include <botan/asn1_obj.h>
12#include <botan/data_src.h>
13#include <botan/mem_ops.h>
42 explicit BER_Decoder(
const std::vector<uint8_t>& vec);
70 ber = get_next_object();
91 bool more_items()
const;
118 return start_cons(
ASN1_Type(tag), ASN1_Class::ContextSpecific);
122 return start_cons(
ASN1_Type(tag), ASN1_Class::ExplicitContextSpecific);
141 template <
typename T>
143 requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
148 if(obj.
length() !=
sizeof(
T)) {
150 "; Output type size is " + std::to_string(
sizeof(
T)));
161 template <
typename Alloc>
165 while(m_source->read_byte(buf)) {
189 std::vector<uint8_t> out_vec;
190 decode(out_vec, ASN1_Type::OctetString);
197 template <
typename Alloc>
199 return decode(out, real_type, real_type, ASN1_Class::Universal);
211 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
216 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
219 ASN1_Type type_tag = ASN1_Type::NoObject,
227 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
ASN1_Class class_tag,
size_t T_bytes);
229 template <
typename T>
231 return decode_integer_type<T>(out, ASN1_Type::Integer, ASN1_Class::Universal);
234 template <
typename T>
236 out =
static_cast<T>(decode_constrained_integer(type_tag, class_tag,
sizeof(out)));
240 template <
typename T>
243 template <
typename T>
249 const T& default_value =
T());
251 template <
typename T>
253 ASN1_Type type_tag = ASN1_Type::Sequence,
254 ASN1_Class class_tag = ASN1_Class::Universal);
256 template <
typename T>
261 if(actual != expected) {
271 template <
typename Alloc>
274 uint32_t expected_tag,
275 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
280 if(obj.
is_a(type_tag, class_tag)) {
281 if(class_tag == ASN1_Class::ExplicitContextSpecific) {
284 push_back(std::move(obj));
285 decode(out, real_type, type_tag, class_tag);
289 push_back(std::move(obj));
295 template <
typename Alloc>
299 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
300 return decode_optional_string(out, real_type,
static_cast<uint32_t
>(expected_tag), class_tag);
310 mutable std::unique_ptr<DataSource> m_data_src;
320 if(obj.
is_a(type_tag, class_tag)) {
322 BER_Decoder(std::move(obj)).decode(out).verify_end();
325 decode(out, type_tag, class_tag);
344 const T& default_value) {
347 if(obj.
is_a(type_tag, class_tag)) {
348 obj.set_tagging(real_type, real_class);
350 decode(out, real_type, real_class);
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)
void push_back(const BER_Object &obj)
BER_Object get_next_object()
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_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(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)
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
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
@ ExplicitContextSpecific
std::vector< T, secure_allocator< T > > secure_vector
constexpr void copy_mem(T *out, const T *in, size_t n)