summaryrefslogtreecommitdiff
path: root/asn.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-09-29 23:28:30 -0400
committerJeffrey Walton <noloader@gmail.com>2019-09-29 23:28:30 -0400
commitd850788574e68742bd936e6a026c62c1839abaab (patch)
tree76a3f9727c7c77c1c0ebf86d92f1ec26e8036373 /asn.cpp
parentdb22c6ce50cb5e3900acc24695c2055ccc51e930 (diff)
downloadcryptopp-git-d850788574e68742bd936e6a026c62c1839abaab.tar.gz
Add DEREncodeTextString overload
Diffstat (limited to 'asn.cpp')
-rw-r--r--asn.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/asn.cpp b/asn.cpp
index e6f3c895..729c7760 100644
--- a/asn.cpp
+++ b/asn.cpp
@@ -148,12 +148,22 @@ size_t BERDecodeOctetString(BufferedTransformation &bt, BufferedTransformation &
return bc;
}
-size_t DEREncodeTextString(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
+size_t DEREncodeTextString(BufferedTransformation &bt, const byte* str, size_t strLen, byte asnTag)
{
bt.Put(asnTag);
- size_t lengthBytes = DERLengthEncode(bt, str.size());
- bt.Put(ConstBytePtr(str), BytePtrSize(str));
- return 1+lengthBytes+str.size();
+ size_t lengthBytes = DERLengthEncode(bt, strLen);
+ bt.Put(str, strLen);
+ return 1+lengthBytes+strLen;
+}
+
+size_t DEREncodeTextString(BufferedTransformation &bt, const SecByteBlock &str, byte asnTag)
+{
+ return DEREncodeTextString(bt, ConstBytePtr(str), BytePtrSize(str), asnTag);
+}
+
+size_t DEREncodeTextString(BufferedTransformation &bt, const std::string &str, byte asnTag)
+{
+ return DEREncodeTextString(bt, ConstBytePtr(str), BytePtrSize(str), asnTag);
}
size_t BERDecodeTextString(BufferedTransformation &bt, SecByteBlock &str, byte asnTag)
@@ -276,11 +286,13 @@ void DERReencode(BufferedTransformation &source, BufferedTransformation &dest)
size_t BERDecodePeekLength(BufferedTransformation &bt)
{
ByteQueue tagAndLength;
- bt.CopyTo(tagAndLength, 9);
+ lword count = (std::min)(bt.MaxRetrievable(), static_cast<lword>(16));
+ bt.CopyTo(tagAndLength, count);
// Skip tag
tagAndLength.Skip(1);
+ // BERLengthDecode fails for indefinite length.
size_t length;
if (!BERLengthDecode(tagAndLength, length))
return 0;