aboutsummaryrefslogtreecommitdiffstats
path: root/src/cert
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-06-22 13:43:18 +0000
committerlloyd <[email protected]>2010-06-22 13:43:18 +0000
commit54bac11c5d4e051f996951feb6a037b1de001329 (patch)
tree8cfa3b72ae36dcd156c4ab4dae1066ee3e021830 /src/cert
parent991f744c5a3e9610a2e4af70ae5daeb7a943a38e (diff)
parent238869aed29c3d703650ce55404929dc7e3f31fb (diff)
propagate from branch 'net.randombit.botan' (head 647eeb4f4cf8fa4cf487cdc463d48f09fe18658e)
to branch 'net.randombit.botan.c++0x' (head 2539675db91883b11895ddc5244721e93c413321)
Diffstat (limited to 'src/cert')
-rw-r--r--src/cert/x509/x509_obj.cpp34
-rw-r--r--src/cert/x509/x509_obj.h36
2 files changed, 46 insertions, 24 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);
}
/*
diff --git a/src/cert/x509/x509_obj.h b/src/cert/x509/x509_obj.h
index 52b76d218..28ee95073 100644
--- a/src/cert/x509/x509_obj.h
+++ b/src/cert/x509/x509_obj.h
@@ -23,8 +23,21 @@ namespace Botan {
class BOTAN_DLL X509_Object
{
public:
+
+ /**
+ * The underlying data that is to be or was signed
+ * @return data that is or was signed
+ */
SecureVector<byte> tbs_data() const;
+
+ /**
+ * @return signature on tbs_data()
+ */
SecureVector<byte> signature() const;
+
+ /**
+ * @return signature algorithm that was used to generate signature
+ */
AlgorithmIdentifier signature_algorithm() const;
/**
@@ -40,10 +53,29 @@ class BOTAN_DLL X509_Object
const AlgorithmIdentifier& alg_id,
const MemoryRegion<byte>& tbs);
- bool check_signature(class Public_Key&) const;
+ /**
+ * Check the signature on this data
+ * @param key the public key purportedly used to sign this data
+ * @return true if the signature is valid, otherwise false
+ */
+ bool check_signature(class Public_Key& key) const;
- void encode(Pipe&, X509_Encoding = PEM) const;
+ /**
+ * Encode this to a pipe
+ * @deprecated use BER_encode or PEM_encode instead
+ * @param out the pipe to write to
+ * @param encoding the encoding to use
+ */
+ void encode(Pipe& out, X509_Encoding encoding = PEM) const;
+
+ /**
+ * @return BER encoding of this
+ */
SecureVector<byte> BER_encode() const;
+
+ /**
+ * @return PEM encoding of this
+ */
std::string PEM_encode() const;
X509_Object(DataSource&, const std::string&);