diff options
Diffstat (limited to 'src/cert/x509/x509_obj.cpp')
-rw-r--r-- | src/cert/x509/x509_obj.cpp | 34 |
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); } /* |