8 #ifndef BOTAN_DER_ENCODER_H_
9 #define BOTAN_DER_ENCODER_H_
11 #include <botan/asn1_obj.h>
25 typedef std::function<void (const uint8_t[], size_t)>
append_fn;
61 std::vector<uint8_t> BOTAN_DEPRECATED(
"Use DER_Encoder(vector) instead") get_contents_unlocked();
73 DER_Encoder& raw_bytes(const uint8_t val[],
size_t len);
75 template<typename Alloc>
78 return raw_bytes(val.data(), val.size());
87 template<
typename Alloc>
90 return encode(vec.data(), vec.size(), real_type);
110 template<
typename Alloc>
115 return encode(bytes.data(), bytes.size(),
116 real_type, type_tag, class_tag);
122 if(value != default_value)
130 for(
size_t i = 0; i != values.size(); ++i)
158 const uint8_t rep[],
size_t length);
161 const std::vector<uint8_t>& rep)
163 return add_object(type_tag, class_tag, rep.data(), rep.size());
169 return add_object(type_tag, class_tag, rep.data(), rep.size());
173 const std::string& str);
179 class DER_Sequence
final
186 void add_bytes(
const uint8_t val[],
size_t len);
188 void add_bytes(
const uint8_t hdr[],
size_t hdr_len,
189 const uint8_t val[],
size_t val_len);
193 DER_Sequence(DER_Sequence&& seq)
195 std::swap(m_type_tag, seq.m_type_tag);
196 std::swap(m_class_tag, seq.m_class_tag);
197 std::swap(m_contents, seq.m_contents);
198 std::swap(m_set_contents, seq.m_set_contents);
201 DER_Sequence& operator=(DER_Sequence&& seq)
203 std::swap(m_type_tag, seq.m_type_tag);
204 std::swap(m_class_tag, seq.m_class_tag);
205 std::swap(m_contents, seq.m_contents);
206 std::swap(m_set_contents, seq.m_set_contents);
210 DER_Sequence(
const DER_Sequence& seq) =
default;
212 DER_Sequence& operator=(
const DER_Sequence& seq) =
default;
216 secure_vector<uint8_t> m_contents;
217 std::vector< secure_vector<uint8_t> > m_set_contents;
220 append_fn m_append_output;
221 secure_vector<uint8_t> m_default_outbuf;
222 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)