aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/x509_key.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-17 21:48:55 +0000
committerlloyd <[email protected]>2010-06-17 21:48:55 +0000
commitc06b260b3328c5ce4be44c4f1a88feb55ee3dbc4 (patch)
tree41b05df5982b5b2e8a23b55972263d2172d6a9fd /src/pubkey/x509_key.cpp
parent0eecae9f21172c0a74ad62acaf77148c94a25be7 (diff)
parent3dde5683f69b9cb9f558bfb18087ce35fbbec78a (diff)
propagate from branch 'net.randombit.botan' (head 294e2082ce9231d6165276e2f2a4153a0116aca3)
to branch 'net.randombit.botan.c++0x' (head 0b695fad10f924601e07b009fcd781191fafcb28)
Diffstat (limited to 'src/pubkey/x509_key.cpp')
-rw-r--r--src/pubkey/x509_key.cpp28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/pubkey/x509_key.cpp b/src/pubkey/x509_key.cpp
index babeb517f..d321ce338 100644
--- a/src/pubkey/x509_key.cpp
+++ b/src/pubkey/x509_key.cpp
@@ -1,6 +1,6 @@
/*
* X.509 Public Key
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -18,23 +18,14 @@ namespace Botan {
namespace X509 {
-/*
-* DER or PEM encode a X.509 public key
-*/
-void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding)
+MemoryVector<byte> BER_encode(const Public_Key& key)
{
- MemoryVector<byte> der =
- DER_Encoder()
+ return DER_Encoder()
.start_cons(SEQUENCE)
.encode(key.algorithm_identifier())
.encode(key.x509_subject_public_key(), BIT_STRING)
.end_cons()
.get_contents();
-
- if(encoding == PEM)
- pipe.write(PEM_Code::encode(der, "PUBLIC KEY"));
- else
- pipe.write(der);
}
/*
@@ -42,11 +33,8 @@ void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding)
*/
std::string PEM_encode(const Public_Key& key)
{
- Pipe pem;
- pem.start_msg();
- encode(key, pem, PEM);
- pem.end_msg();
- return pem.read_all_as_string();
+ return PEM_Code::encode(X509::BER_encode(key),
+ "PUBLIC KEY");
}
/*
@@ -115,11 +103,7 @@ Public_Key* load_key(const MemoryRegion<byte>& mem)
*/
Public_Key* copy_key(const Public_Key& key)
{
- Pipe bits;
- bits.start_msg();
- X509::encode(key, bits, RAW_BER);
- bits.end_msg();
- DataSource_Memory source(bits.read_all());
+ DataSource_Memory source(PEM_encode(key));
return X509::load_key(source);
}