aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-21 21:51:55 +0000
committerlloyd <[email protected]>2010-06-21 21:51:55 +0000
commitcf669aa523bff00b2a342c32fb933a7270ed30b7 (patch)
treeb10ac6dea9c82b8d9cd83f7e9bf675617e6d9b59 /src
parent851b9bb998632713d68ea0639394f7e84b48f0e3 (diff)
Define X509_Object::encode in terms of BER_encode and PEM_encode
Diffstat (limited to 'src')
-rw-r--r--src/cert/x509/x509_obj.cpp34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/cert/x509/x509_obj.cpp b/src/cert/x509/x509_obj.cpp
index 1c8066c56..ffee74f12 100644
--- a/src/cert/x509/x509_obj.cpp
+++ b/src/cert/x509/x509_obj.cpp
@@ -88,20 +88,10 @@ void X509_Object::decode_info(DataSource& source)
*/
void X509_Object::encode(Pipe& out, X509_Encoding encoding) const
{
- SecureVector<byte> der = DER_Encoder()
- .start_cons(SEQUENCE)
- .start_cons(SEQUENCE)
- .raw_bytes(tbs_bits)
- .end_cons()
- .encode(sig_algo)
- .encode(sig, BIT_STRING)
- .end_cons()
- .get_contents();
-
if(encoding == PEM)
- out.write(PEM_Code::encode(der, PEM_label_pref));
+ out.write(this->PEM_encode());
else
- out.write(der);
+ out.write(this->BER_encode());
}
/*
@@ -109,11 +99,15 @@ void X509_Object::encode(Pipe& out, X509_Encoding encoding) const
*/
SecureVector<byte> X509_Object::BER_encode() const
{
- Pipe ber;
- ber.start_msg();
- encode(ber, RAW_BER);
- ber.end_msg();
- return ber.read_all();
+ return DER_Encoder()
+ .start_cons(SEQUENCE)
+ .start_cons(SEQUENCE)
+ .raw_bytes(tbs_bits)
+ .end_cons()
+ .encode(sig_algo)
+ .encode(sig, BIT_STRING)
+ .end_cons()
+ .get_contents();
}
/*
@@ -121,11 +115,7 @@ SecureVector<byte> X509_Object::BER_encode() const
*/
std::string X509_Object::PEM_encode() const
{
- Pipe pem;
- pem.start_msg();
- encode(pem, PEM);
- pem.end_msg();
- return pem.read_all_as_string();
+ return PEM_Code::encode(BER_encode(), PEM_label_pref);
}
/*