aboutsummaryrefslogtreecommitdiffstats
path: root/src/if_algo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/if_algo.cpp')
-rw-r--r--src/if_algo.cpp84
1 files changed, 62 insertions, 22 deletions
diff --git a/src/if_algo.cpp b/src/if_algo.cpp
index 36d859282..3668580b3 100644
--- a/src/if_algo.cpp
+++ b/src/if_algo.cpp
@@ -11,45 +11,85 @@
namespace Botan {
/*************************************************
-* Return the X.509 public key encoding *
+* Return the X.509 public key encoder *
*************************************************/
-MemoryVector<byte> IF_Scheme_PublicKey::DER_encode_pub() const
+X509_Encoder* IF_Scheme_PublicKey::x509_encoder() const
{
- return DER_Encoder()
- .start_cons(SEQUENCE)
- .encode(n)
- .encode(e)
- .end_cons()
- .get_contents();
+ class IF_Algo_Encoder : public X509_Encoder
+ {
+ public:
+ AlgorithmIdentifier alg_id() const
+ {
+ return AlgorithmIdentifier(oid,
+ AlgorithmIdentifier::USE_NULL_PARAM);
+ }
+
+ MemoryVector<byte> key_bits() const
+ {
+ return DER_Encoder()
+ .start_cons(SEQUENCE)
+ .encode(n)
+ .encode(e)
+ .end_cons()
+ .get_contents();
+ }
+
+ IF_Algo_Encoder(const OID& oid, const BigInt& n, const BigInt& e)
+ {
+ this->oid = oid;
+ this->n = n;
+ this->e = e;
+ }
+ private:
+ OID oid;
+ BigInt n, e;
+ };
+
+ return new IF_Algo_Encoder(get_oid(), n, e);
}
/*************************************************
-* Return the X.509 parameters encoding *
+* Return the X.509 public key decoder *
*************************************************/
-MemoryVector<byte> IF_Scheme_PublicKey::DER_encode_params() const
+X509_Decoder* IF_Scheme_PublicKey::x509_decoder()
{
- return DER_Encoder().encode_null().get_contents();
+ class IF_Algo_Decoder : public X509_Decoder
+ {
+ public:
+ void alg_id(const AlgorithmIdentifier&) {}
+
+ void key_bits(const MemoryRegion<byte>& bits)
+ {
+ BER_Decoder(bits)
+ .start_cons(SEQUENCE)
+ .decode(key->n)
+ .decode(key->e)
+ .verify_end()
+ .end_cons();
+
+ key->X509_load_hook();
+ }
+
+ IF_Algo_Decoder(IF_Scheme_PublicKey* k) : key(k) {}
+ private:
+ IF_Scheme_PublicKey* key;
+ };
+
+ return new IF_Algo_Decoder(this);
}
/*************************************************
-* Decode X.509 public key encoding *
+* Return the X.509 parameters encoding *
*************************************************/
-void IF_Scheme_PublicKey::BER_decode_pub(DataSource& source)
+MemoryVector<byte> IF_Scheme_PrivateKey::DER_encode_params() const
{
- BER_Decoder(source)
- .start_cons(SEQUENCE)
- .decode(n)
- .decode(e)
- .verify_end()
- .end_cons();
-
- X509_load_hook();
+ return DER_Encoder().encode_null().get_contents();
}
/*************************************************
* Decode X.509 algorithm parameters *
*************************************************/
-void IF_Scheme_PublicKey::BER_decode_params(DataSource& source)
+void IF_Scheme_PrivateKey::BER_decode_params(DataSource& source)
{
byte dummy = 0;
while(!source.end_of_data())