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);
69 ber = get_next_object();
90 bool more_items()
const;
117 return start_cons(
ASN1_Type(tag), ASN1_Class::ContextSpecific);
121 return start_cons(
ASN1_Type(tag), ASN1_Class::ExplicitContextSpecific);
140 template <
typename T>
142 requires std::is_standard_layout<T>::value && std::is_trivial<T>::value
149 "; Output type size is " + std::to_string(
sizeof(
T)));
159 template <
typename Alloc>
160 BER_Decoder& raw_bytes(std::vector<uint8_t, Alloc>& out) {
163 while(m_source->read_byte(buf))
168 BER_Decoder& decode_null();
186 std::vector<uint8_t> out_vec;
187 decode(out_vec, ASN1_Type::OctetString);
194 template <
typename Alloc>
196 return decode(out, real_type, real_type, ASN1_Class::Universal);
208 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
213 ASN1_Class class_tag = ASN1_Class::ContextSpecific);
216 ASN1_Type type_tag = ASN1_Type::NoObject,
224 uint64_t decode_constrained_integer(
ASN1_Type type_tag,
ASN1_Class class_tag,
size_t T_bytes);
226 template <
typename T>
228 return decode_integer_type<T>(out, ASN1_Type::Integer, ASN1_Class::Universal);
231 template <
typename T>
233 out =
static_cast<T>(decode_constrained_integer(type_tag, class_tag,
sizeof(out)));
237 template <
typename T>
240 template <
typename T>
246 const T& default_value =
T());
248 template <
typename T>
250 ASN1_Type type_tag = ASN1_Type::Sequence,
251 ASN1_Class class_tag = ASN1_Class::Universal);
253 template <
typename T>
258 if(actual != expected)
267 template <
typename Alloc>
270 uint32_t expected_tag,
271 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
276 if(obj.
is_a(type_tag, class_tag)) {
277 if(class_tag == ASN1_Class::ExplicitContextSpecific) {
280 push_back(std::move(obj));
281 decode(out, real_type, type_tag, class_tag);
285 push_back(std::move(obj));
291 template <
typename Alloc>
295 ASN1_Class class_tag = ASN1_Class::ContextSpecific) {
296 return decode_optional_string(out, real_type,
static_cast<uint32_t
>(expected_tag), class_tag);
306 mutable std::unique_ptr<DataSource> m_data_src;
316 if(obj.
is_a(type_tag, class_tag)) {
321 decode(out, type_tag, class_tag);
340 const T& default_value) {
343 if(obj.
is_a(type_tag, class_tag)) {
344 obj.set_tagging(real_type, real_class);
346 decode(out, real_type, real_class);
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 & 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 & get_next_value(T &out, ASN1_Type type_tag, ASN1_Class class_tag=ASN1_Class::ContextSpecific)
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
constexpr void copy_mem(T *out, const T *in, size_t n)
std::vector< T, secure_allocator< T > > secure_vector