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();
101 bool more_items()
const;
128 return start_cons(
ASN1_Type(tag), ASN1_Class::ContextSpecific);
132 return start_cons(
ASN1_Type(tag), ASN1_Class::ExplicitContextSpecific);
151 template <
typename T>
153 requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
158 if(obj.
length() !=
sizeof(
T)) {
160 "; Output type size is " + std::to_string(
sizeof(
T)));
171 template <
typename Alloc>
175 while(m_source->read_byte(buf)) {
199 std::vector<uint8_t> out_vec;
200 decode(out_vec, ASN1_Type::OctetString);
207 template <
typename Alloc>
209 return decode(out, real_type, real_type, ASN1_Class::Universal);
221 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
226 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
229 ASN1_Type type_tag = ASN1_Type::NoObject,
237 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
ASN1_Class class_tag,
size_t T_bytes);
239 template <
typename T>
241 return decode_integer_type<T>(out, ASN1_Type::Integer, ASN1_Class::Universal);
244 template <
typename T>
246 out =
static_cast<T>(decode_constrained_integer(type_tag, class_tag,
sizeof(out)));
250 template <
typename T>
253 template <
typename T>
259 const T& default_value =
T());
261 template <
typename T>
263 ASN1_Type type_tag = ASN1_Type::Sequence,
264 ASN1_Class class_tag = ASN1_Class::Universal);
266 template <
typename T>
267 bool decode_optional_list(std::vector<T>& out,
268 ASN1_Type type_tag = ASN1_Type::Sequence,
269 ASN1_Class class_tag = ASN1_Class::Universal);
271 template <
typename T>
276 if(actual != expected) {
286 template <
typename Alloc>
289 uint32_t expected_tag,
290 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
295 if(obj.
is_a(type_tag, class_tag)) {
296 if(class_tag == ASN1_Class::ExplicitContextSpecific) {
299 push_back(std::move(obj));
300 decode(out, real_type, type_tag, class_tag);
304 push_back(std::move(obj));
310 template <
typename Alloc>
314 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
315 return decode_optional_string(out, real_type,
static_cast<uint32_t
>(expected_tag), class_tag);
325 mutable std::unique_ptr<DataSource> m_data_src;
335 if(obj.
is_a(type_tag, class_tag)) {
337 BER_Decoder(std::move(obj)).decode(out).verify_end();
340 decode(out, type_tag, class_tag);
359 const T& default_value) {
362 if(obj.
is_a(type_tag, class_tag)) {
363 obj.set_tagging(real_type, real_class);
365 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)
const BER_Object & peek_next_object()
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)
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
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)