aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/asn1/der_enc.h
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-05-22 11:04:15 -0400
committerJack Lloyd <[email protected]>2018-05-22 11:04:15 -0400
commit3789138906cecbcc5e33bb0d5784e6b576171080 (patch)
tree147c442020bec8ad6effe62727fdb6b300d0f7f7 /src/lib/asn1/der_enc.h
parentcd0bcd90817ece3e4fcba32e06a372580bbe3008 (diff)
DER improvements
Let DER_Encoder write to a user specified vector instead of only to an internal vector. This allows encoding to a std::vector without having to first write to a locked vector and then copying out the result. Add ASN1_Object::BER_encode convenience method. Replaces X509_Object::BER_encode which had the same logic but was restricted to a subtype. This replaces many cases where DER_Encoder was just used to encode a single object (X509_DN, AlgorithmIdentifier, etc).
Diffstat (limited to 'src/lib/asn1/der_enc.h')
-rw-r--r--src/lib/asn1/der_enc.h23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lib/asn1/der_enc.h b/src/lib/asn1/der_enc.h
index ebca73d33..f351817f9 100644
--- a/src/lib/asn1/der_enc.h
+++ b/src/lib/asn1/der_enc.h
@@ -10,6 +10,7 @@
#include <botan/asn1_obj.h>
#include <vector>
+#include <functional>
namespace Botan {
@@ -22,6 +23,25 @@ class ASN1_Object;
class BOTAN_PUBLIC_API(2,0) DER_Encoder final
{
public:
+ /**
+ * DER encode, writing to an internal buffer
+ * Use get_contents or get_contents_unlocked to read the results
+ * after all encoding is completed.
+ */
+ DER_Encoder() = default;
+
+ /**
+ * DER encode, writing to @param vec
+ * If this constructor is used, get_contents* may not be called.
+ */
+ DER_Encoder(secure_vector<uint8_t>& vec);
+
+ /**
+ * DER encode, writing to @param vec
+ * If this constructor is used, get_contents* may not be called.
+ */
+ DER_Encoder(std::vector<uint8_t>& vec);
+
secure_vector<uint8_t> get_contents();
std::vector<uint8_t> get_contents_unlocked();
@@ -183,7 +203,8 @@ class BOTAN_PUBLIC_API(2,0) DER_Encoder final
std::vector< secure_vector<uint8_t> > m_set_contents;
};
- secure_vector<uint8_t> m_contents;
+ std::function<void (const uint8_t[], size_t)> m_append_output_fn;
+ secure_vector<uint8_t> m_default_outbuf;
std::vector<DER_Sequence> m_subsequences;
};