aboutsummaryrefslogtreecommitdiffstats
path: root/src/dl_algo.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-09-06 06:27:20 +0000
committerlloyd <[email protected]>2006-09-06 06:27:20 +0000
commit0df4cf5008f0a4f6c259dc7bcd64079e5810eb80 (patch)
tree8475c9f40e1f9b2f23053e8ffa93502a688c3f89 /src/dl_algo.cpp
parent219aa8f6b449f7dc81ddae48c4b01328ffe69cd3 (diff)
First step in a major rewrite of the high level public key code. The
X509_PublicKey object now offers interfaces that return encoder and decoder objects. Eventually these changes will make it much easier to support alternate key formats like OpenPGP.
Diffstat (limited to 'src/dl_algo.cpp')
-rw-r--r--src/dl_algo.cpp73
1 files changed, 59 insertions, 14 deletions
diff --git a/src/dl_algo.cpp b/src/dl_algo.cpp
index 6e61a672b..731a652d2 100644
--- a/src/dl_algo.cpp
+++ b/src/dl_algo.cpp
@@ -11,37 +11,82 @@
namespace Botan {
/*************************************************
-* Return the X.509 public key encoding *
+* Return the X.509 public key encoder *
*************************************************/
-MemoryVector<byte> DL_Scheme_PublicKey::DER_encode_pub() const
+X509_Encoder* DL_Scheme_PublicKey::x509_encoder() const
{
- return DER_Encoder().encode(y).get_contents();
+ class DL_Algo_Encoder : public X509_Encoder
+ {
+ public:
+ AlgorithmIdentifier alg_id() const
+ {
+ return AlgorithmIdentifier(oid, group.DER_encode(group_format));
+ }
+
+ MemoryVector<byte> key_bits() const
+ {
+ return DER_Encoder().encode(y).get_contents();
+ }
+
+ DL_Algo_Encoder(const OID& oid, const BigInt& y,
+ const DL_Group& group,
+ const DL_Group::Format group_format)
+ {
+ this->oid = oid;
+ this->y = y;
+ this->group = group;
+ this->group_format = group_format;
+ }
+ private:
+ OID oid;
+ BigInt y;
+ DL_Group group;
+ DL_Group::Format group_format;
+ };
+
+ return new DL_Algo_Encoder(get_oid(), y, group, group_format());
}
/*************************************************
-* Return the X.509 parameters encoding *
+* Return the X.509 public key decoder *
*************************************************/
-MemoryVector<byte> DL_Scheme_PublicKey::DER_encode_params() const
+X509_Decoder* DL_Scheme_PublicKey::x509_decoder()
{
- return group.DER_encode(group_format());
+ class DL_Algo_Decoder : public X509_Decoder
+ {
+ public:
+ void alg_id(const AlgorithmIdentifier& alg_id)
+ {
+ DataSource_Memory source(alg_id.parameters);
+ key->group.BER_decode(source, key->group_format());
+ }
+
+ void key_bits(const MemoryRegion<byte>& bits)
+ {
+ BER_Decoder(bits).decode(key->y);
+ key->X509_load_hook();
+ }
+
+ DL_Algo_Decoder(DL_Scheme_PublicKey* k) : key(k) {}
+ private:
+ DL_Scheme_PublicKey* key;
+ };
+
+ return new DL_Algo_Decoder(this);
}
/*************************************************
-* Decode X.509 public key encoding *
+* Return the X.509 parameters encoding *
*************************************************/
-void DL_Scheme_PublicKey::BER_decode_pub(DataSource& source)
+MemoryVector<byte> DL_Scheme_PrivateKey::DER_encode_params() const
{
- BER_Decoder(source).decode(y);
-
- if(y < 2 || y >= group_p())
- throw Invalid_Argument(algo_name() + ": Invalid public key");
- X509_load_hook();
+ return group.DER_encode(group_format());
}
/*************************************************
* Decode X.509 algorithm parameters *
*************************************************/
-void DL_Scheme_PublicKey::BER_decode_params(DataSource& source)
+void DL_Scheme_PrivateKey::BER_decode_params(DataSource& source)
{
group.BER_decode(source, group_format());
}