8 #ifndef BOTAN_DER_ENCODER_H_
9 #define BOTAN_DER_ENCODER_H_
11 #include <botan/asn1_obj.h>
26 typedef std::function<void (const uint8_t[], size_t)>
append_fn;
62 std::vector<uint8_t> BOTAN_DEPRECATED(
"Use DER_Encoder(vector) instead") get_contents_unlocked();
74 DER_Encoder& raw_bytes(const uint8_t val[],
size_t len);
76 template<typename Alloc>
79 return raw_bytes(val.data(), val.size());
88 template<
typename Alloc>
91 return encode(vec.data(), vec.size(), real_type);
111 template<
typename Alloc>
116 return encode(bytes.data(), bytes.size(),
117 real_type, type_tag, class_tag);
123 if(value != default_value)
131 for(
size_t i = 0; i != values.size(); ++i)
159 const uint8_t rep[],
size_t length);
162 const std::vector<uint8_t>& rep)
164 return add_object(type_tag, class_tag, rep.data(), rep.size());
170 return add_object(type_tag, class_tag, rep.data(), rep.size());
174 const std::string& str);
180 class DER_Sequence
final
187 void add_bytes(
const uint8_t val[],
size_t len);
189 void add_bytes(
const uint8_t hdr[],
size_t hdr_len,
190 const uint8_t val[],
size_t val_len);
194 DER_Sequence(DER_Sequence&& seq)
196 std::swap(m_type_tag, seq.m_type_tag);
197 std::swap(m_class_tag, seq.m_class_tag);
198 std::swap(m_contents, seq.m_contents);
199 std::swap(m_set_contents, seq.m_set_contents);
202 DER_Sequence& operator=(DER_Sequence&& seq)
204 std::swap(m_type_tag, seq.m_type_tag);
205 std::swap(m_class_tag, seq.m_class_tag);
206 std::swap(m_contents, seq.m_contents);
207 std::swap(m_set_contents, seq.m_set_contents);
211 DER_Sequence(
const DER_Sequence& seq) =
default;
213 DER_Sequence& operator=(
const DER_Sequence& seq) =
default;
217 secure_vector<uint8_t> m_contents;
218 std::vector< secure_vector<uint8_t> > m_set_contents;
221 append_fn m_append_output;
222 secure_vector<uint8_t> m_default_outbuf;
223 std::vector<DER_Sequence> m_subsequences;
DER_Encoder & add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const std::vector< uint8_t > &rep)
DER_Encoder(append_fn append)
DER_Encoder & encode_list(const std::vector< T > &values)
DER_Encoder & encode_optional(const T &value, const T &default_value)
DER_Encoder & encode(const std::vector< uint8_t, Alloc > &vec, ASN1_Tag real_type)
DER_Encoder & encode_if(bool pred, const ASN1_Object &obj)
std::function< void(const uint8_t[], size_t)> append_fn
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
secure_vector< uint8_t > get_contents()
DER_Encoder & encode_if(bool pred, DER_Encoder &enc)
std::vector< T, secure_allocator< T >> secure_vector
DER_Encoder & encode(const std::vector< uint8_t, Alloc > &bytes, ASN1_Tag real_type, ASN1_Tag type_tag, ASN1_Tag class_tag)
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
DER_Encoder & add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const secure_vector< uint8_t > &rep)