summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2019-09-29 15:09:25 -0400
committerJeffrey Walton <noloader@gmail.com>2019-09-29 15:09:25 -0400
commit7a927b4d8270c017d533a29f1e21be8c6d595ba9 (patch)
treeeb5973f36b717a5fa90ecf58073860f1a55d2d40
parentbf8a765c32acf7d5b32bbcfc4642e5fe3ad9a9b4 (diff)
downloadcryptopp-git-7a927b4d8270c017d533a29f1e21be8c6d595ba9.tar.gz
Update BERDecodeTextString
-rw-r--r--asn.cpp20
-rw-r--r--asn.h8
2 files changed, 21 insertions, 7 deletions
diff --git a/asn.cpp b/asn.cpp
index ed4ac82f..b2e86e06 100644
--- a/asn.cpp
+++ b/asn.cpp
@@ -168,13 +168,10 @@ size_t BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte as
if (bc > bt.MaxRetrievable()) // Issue 346
BERDecodeError();
- SecByteBlock temp(bc);
- if (bc != bt.Get(temp, bc))
+ str.resize(bc);
+ if (bc != bt.Get(BytePtr(str), BytePtrSize(str)))
BERDecodeError();
- if (bc)
- str.assign((char *)temp.begin(), bc);
- else
- str.clear();
+
return bc;
}
@@ -304,6 +301,17 @@ void OID::BERDecodeAndCheck(BufferedTransformation &bt) const
BERDecodeError();
}
+std::ostream& OID::Print(std::ostream& out) const
+{
+ for (size_t i = 0; i < m_values.size(); ++i)
+ {
+ out << m_values[i];
+ if (i+1 < m_values.size())
+ out << ".";
+ }
+ return out;
+}
+
inline BufferedTransformation & EncodedObjectFilter::CurrentTarget()
{
if (m_flags & PUT_OBJECTS)
diff --git a/asn.h b/asn.h
index d6e4f7e0..18d4fd73 100644
--- a/asn.h
+++ b/asn.h
@@ -13,6 +13,8 @@
#include "queue.h"
#include "misc.h"
+#include <iosfwd>
+
// Issue 340
#if CRYPTOPP_GCC_DIAGNOSTIC_AVAILABLE
# pragma GCC diagnostic push
@@ -138,7 +140,7 @@ CRYPTOPP_DLL size_t CRYPTOPP_API DEREncodeTextString(BufferedTransformation &bt,
/// \param bt BufferedTransformation object for reading
/// \param str the string to encode
/// \param asnTag the ASN.1 type
-/// \details DEREncodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
+/// \details BERDecodeTextString() can be used for UTF8_STRING, PRINTABLE_STRING, and IA5_STRING
CRYPTOPP_DLL size_t CRYPTOPP_API BERDecodeTextString(BufferedTransformation &bt, std::string &str, byte asnTag);
/// \brief DER encode bit string
@@ -207,6 +209,8 @@ public:
return m_values;
}
+ std::ostream& Print(std::ostream& out) const;
+
protected:
friend bool operator==(const OID &lhs, const OID &rhs);
friend bool operator!=(const OID &lhs, const OID &rhs);
@@ -805,6 +809,8 @@ inline bool operator<(const ::CryptoPP::OID &lhs, const ::CryptoPP::OID &rhs)
{return std::lexicographical_compare(lhs.m_values.begin(), lhs.m_values.end(), rhs.m_values.begin(), rhs.m_values.end());}
inline ::CryptoPP::OID operator+(const ::CryptoPP::OID &lhs, unsigned long rhs)
{return ::CryptoPP::OID(lhs)+=rhs;}
+inline std::ostream& operator<<(std::ostream& out, const OID &oid)
+ { return oid.Print(out); }
#endif
NAMESPACE_END