aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-04 02:07:14 +0000
committerlloyd <[email protected]>2010-03-04 02:07:14 +0000
commitc58d02b152b11bae78985aa441560f49ef6b5d09 (patch)
treec01bbbbe6ee86f60faf238a271c28dd03326ac5c /src/pubkey
parentf109029f5f1cc33512091e228e6ee6532058c42f (diff)
Add a new function to public key x509_subject_public_key which returns
what x509_encoder()->key_bits() used to return. This is much simpler than using the explicit encoder objects. Remove X509_Encoder entirely.
Diffstat (limited to 'src/pubkey')
-rw-r--r--src/pubkey/dl_algo/dl_algo.cpp25
-rw-r--r--src/pubkey/dl_algo/dl_algo.h8
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp28
-rw-r--r--src/pubkey/ecc_key/ecc_key.h8
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp35
-rw-r--r--src/pubkey/gost_3410/gost_3410.h8
-rw-r--r--src/pubkey/if_algo/if_algo.cpp35
-rw-r--r--src/pubkey/if_algo/if_algo.h3
-rw-r--r--src/pubkey/pk_codecs/x509_key.cpp8
-rw-r--r--src/pubkey/pk_codecs/x509_key.h11
-rw-r--r--src/pubkey/pk_keys.h5
11 files changed, 34 insertions, 140 deletions
diff --git a/src/pubkey/dl_algo/dl_algo.cpp b/src/pubkey/dl_algo/dl_algo.cpp
index beaf10695..b8f96bcf1 100644
--- a/src/pubkey/dl_algo/dl_algo.cpp
+++ b/src/pubkey/dl_algo/dl_algo.cpp
@@ -18,30 +18,9 @@ AlgorithmIdentifier DL_Scheme_PublicKey::algorithm_identifier() const
group.DER_encode(group_format()));
}
-/*
-* Return the X.509 public key encoder
-*/
-X509_Encoder* DL_Scheme_PublicKey::x509_encoder() const
+MemoryVector<byte> DL_Scheme_PublicKey::x509_subject_public_key() const
{
- class DL_Scheme_Encoder : public X509_Encoder
- {
- public:
- AlgorithmIdentifier alg_id() const
- {
- return key->algorithm_identifier();
- }
-
- MemoryVector<byte> key_bits() const
- {
- return DER_Encoder().encode(key->y).get_contents();
- }
-
- DL_Scheme_Encoder(const DL_Scheme_PublicKey* k) : key(k) {}
- private:
- const DL_Scheme_PublicKey* key;
- };
-
- return new DL_Scheme_Encoder(this);
+ return DER_Encoder().encode(y).get_contents();
}
/*
diff --git a/src/pubkey/dl_algo/dl_algo.h b/src/pubkey/dl_algo/dl_algo.h
index 1fa99a49b..63875d27b 100644
--- a/src/pubkey/dl_algo/dl_algo.h
+++ b/src/pubkey/dl_algo/dl_algo.h
@@ -25,6 +25,8 @@ class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key
AlgorithmIdentifier algorithm_identifier() const;
+ MemoryVector<byte> x509_subject_public_key() const;
+
/**
* Get the DL domain parameters of this key.
* @return the DL domain parameters of this key
@@ -61,12 +63,6 @@ class BOTAN_DLL DL_Scheme_PublicKey : public virtual Public_Key
virtual DL_Group::Format group_format() const = 0;
/**
- * Get an X509 encoder for this key.
- * @return an encoder usable to encode this key.
- */
- X509_Encoder* x509_encoder() const;
-
- /**
* Get an X509 decoder for this key.
* @return an decoder usable to decode a DL key and store the
* values in this instance.
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index 4a0b20d2f..f91f394dc 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -40,6 +40,11 @@ AlgorithmIdentifier EC_PublicKey::algorithm_identifier() const
return AlgorithmIdentifier(get_oid(), DER_domain());
}
+MemoryVector<byte> EC_PublicKey::x509_subject_public_key() const
+ {
+ return EC2OSP(public_point(), PointGFp::COMPRESSED);
+ }
+
void EC_PublicKey::X509_load_hook()
{
try
@@ -52,29 +57,6 @@ void EC_PublicKey::X509_load_hook()
}
}
-X509_Encoder* EC_PublicKey::x509_encoder() const
- {
- class EC_Key_Encoder : public X509_Encoder
- {
- public:
- AlgorithmIdentifier alg_id() const
- {
- return key->algorithm_identifier();
- }
-
- MemoryVector<byte> key_bits() const
- {
- return EC2OSP(key->public_point(), PointGFp::COMPRESSED);
- }
-
- EC_Key_Encoder(const EC_PublicKey* k): key(k) {}
- private:
- const EC_PublicKey* key;
- };
-
- return new EC_Key_Encoder(this);
- }
-
X509_Decoder* EC_PublicKey::x509_decoder()
{
class EC_Key_Decoder : public X509_Decoder
diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h
index 29a08fba6..226427768 100644
--- a/src/pubkey/ecc_key/ecc_key.h
+++ b/src/pubkey/ecc_key/ecc_key.h
@@ -42,6 +42,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key
AlgorithmIdentifier algorithm_identifier() const;
+ MemoryVector<byte> x509_subject_public_key() const;
+
/**
* Get the domain parameters of this key.
* @throw Invalid_State is thrown if the
@@ -71,12 +73,6 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key
{ return domain_encoding; }
/**
- * Get an x509_encoder that can be used to encode this key.
- * @result an x509_encoder for this key
- */
- X509_Encoder* x509_encoder() const;
-
- /**
* Get an x509_decoder that can be used to decode a stored key into
* this key.
* @result an x509_decoder for this key
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index d23229d9b..d36b9e3d4 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -16,37 +16,18 @@
namespace Botan {
-X509_Encoder* GOST_3410_PublicKey::x509_encoder() const
+MemoryVector<byte> GOST_3410_PublicKey::x509_subject_public_key() const
{
- class GOST_3410_Key_Encoder : public X509_Encoder
- {
- public:
- AlgorithmIdentifier alg_id() const
- {
- return AlgorithmIdentifier(key->get_oid(),
- key->DER_domain());
- }
-
- MemoryVector<byte> key_bits() const
- {
- // Trust CryptoPro to come up with something obnoxious
- const BigInt x = key->public_point().get_affine_x();
- const BigInt y = key->public_point().get_affine_y();
+ // Trust CryptoPro to come up with something obnoxious
+ const BigInt& x = public_point().get_affine_x();
+ const BigInt& y = public_point().get_affine_y();
- SecureVector<byte> bits(2*std::max(x.bytes(), y.bytes()));
+ MemoryVector<byte> bits(2*std::max(x.bytes(), y.bytes()));
- y.binary_encode(bits + (bits.size() / 2 - y.bytes()));
- x.binary_encode(bits + (bits.size() - y.bytes()));
-
- return DER_Encoder().encode(bits, OCTET_STRING).get_contents();
- }
-
- GOST_3410_Key_Encoder(const GOST_3410_PublicKey* k): key(k) {}
- private:
- const GOST_3410_PublicKey* key;
- };
+ y.binary_encode(bits + (bits.size() / 2 - y.bytes()));
+ x.binary_encode(bits + (bits.size() - y.bytes()));
- return new GOST_3410_Key_Encoder(this);
+ return DER_Encoder().encode(bits, OCTET_STRING).get_contents();
}
X509_Decoder* GOST_3410_PublicKey::x509_decoder()
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index 6daa0eaf8..c1cd0d293 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -28,6 +28,8 @@ class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey,
*/
std::string algo_name() const { return "GOST-34.10"; }
+ MemoryVector<byte> x509_subject_public_key() const;
+
/**
* Get the maximum number of bits allowed to be fed to this key.
* This is the bitlength of the order of the base point.
@@ -67,12 +69,6 @@ class BOTAN_DLL GOST_3410_PublicKey : public virtual EC_PublicKey,
EC_PublicKey(dom_par, public_point) {}
/**
- * Get an x509_encoder that can be used to encode this key.
- * @result an x509_encoder for this key
- */
- X509_Encoder* x509_encoder() const;
-
- /**
* Get an x509_decoder that can be used to decode a stored key into
* this key.
* @result an x509_decoder for this key
diff --git a/src/pubkey/if_algo/if_algo.cpp b/src/pubkey/if_algo/if_algo.cpp
index ee34b1418..2a7b19d3b 100644
--- a/src/pubkey/if_algo/if_algo.cpp
+++ b/src/pubkey/if_algo/if_algo.cpp
@@ -18,35 +18,14 @@ AlgorithmIdentifier IF_Scheme_PublicKey::algorithm_identifier() const
AlgorithmIdentifier::USE_NULL_PARAM);
}
-/*
-* Return the X.509 public key encoder
-*/
-X509_Encoder* IF_Scheme_PublicKey::x509_encoder() const
+MemoryVector<byte> IF_Scheme_PublicKey::x509_subject_public_key() const
{
- class IF_Scheme_Encoder : public X509_Encoder
- {
- public:
- AlgorithmIdentifier alg_id() const
- {
- return key->algorithm_identifier();
- }
-
- MemoryVector<byte> key_bits() const
- {
- return DER_Encoder()
- .start_cons(SEQUENCE)
- .encode(key->n)
- .encode(key->e)
- .end_cons()
- .get_contents();
- }
-
- IF_Scheme_Encoder(const IF_Scheme_PublicKey* k) : key(k) {}
- private:
- const IF_Scheme_PublicKey* key;
- };
-
- return new IF_Scheme_Encoder(this);
+ return DER_Encoder()
+ .start_cons(SEQUENCE)
+ .encode(n)
+ .encode(e)
+ .end_cons()
+ .get_contents();
}
/*
diff --git a/src/pubkey/if_algo/if_algo.h b/src/pubkey/if_algo/if_algo.h
index 98ae070c9..17598dd52 100644
--- a/src/pubkey/if_algo/if_algo.h
+++ b/src/pubkey/if_algo/if_algo.h
@@ -25,6 +25,8 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key
AlgorithmIdentifier algorithm_identifier() const;
+ MemoryVector<byte> x509_subject_public_key() const;
+
/**
* Get n = p * q.
* @return n
@@ -39,7 +41,6 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key
u32bit max_input_bits() const { return (n.bits() - 1); }
- X509_Encoder* x509_encoder() const;
X509_Decoder* x509_decoder();
protected:
virtual void X509_load_hook();
diff --git a/src/pubkey/pk_codecs/x509_key.cpp b/src/pubkey/pk_codecs/x509_key.cpp
index fcfb2b165..fdcfccf87 100644
--- a/src/pubkey/pk_codecs/x509_key.cpp
+++ b/src/pubkey/pk_codecs/x509_key.cpp
@@ -24,15 +24,11 @@ namespace X509 {
*/
void encode(const Public_Key& key, Pipe& pipe, X509_Encoding encoding)
{
- std::auto_ptr<X509_Encoder> encoder(key.x509_encoder());
- if(!encoder.get())
- throw Encoding_Error("X509::encode: Key does not support encoding");
-
MemoryVector<byte> der =
DER_Encoder()
.start_cons(SEQUENCE)
- .encode(encoder->alg_id())
- .encode(encoder->key_bits(), BIT_STRING)
+ .encode(key.algorithm_identifier())
+ .encode(key.x509_subject_public_key(), BIT_STRING)
.end_cons()
.get_contents();
diff --git a/src/pubkey/pk_codecs/x509_key.h b/src/pubkey/pk_codecs/x509_key.h
index 9404b7ecc..a8f5267d7 100644
--- a/src/pubkey/pk_codecs/x509_key.h
+++ b/src/pubkey/pk_codecs/x509_key.h
@@ -16,17 +16,6 @@
namespace Botan {
/**
-* This class represents abstract X.509 public key encoders.
-*/
-class BOTAN_DLL X509_Encoder
- {
- public:
- virtual AlgorithmIdentifier alg_id() const = 0;
- virtual MemoryVector<byte> key_bits() const = 0;
- virtual ~X509_Encoder() {}
- };
-
-/**
* This class represents abstract X.509 public key decoders.
*/
class BOTAN_DLL X509_Decoder
diff --git a/src/pubkey/pk_keys.h b/src/pubkey/pk_keys.h
index 33341b513..d1a841b9a 100644
--- a/src/pubkey/pk_keys.h
+++ b/src/pubkey/pk_keys.h
@@ -67,10 +67,9 @@ class BOTAN_DLL Public_Key
virtual AlgorithmIdentifier algorithm_identifier() const = 0;
/**
- * Get an X509 encoder that can be used to encode this key in X509 format.
- * @return an X509 encoder for this key
+ * @return X.509 subject key encoding for this key object
*/
- virtual class X509_Encoder* x509_encoder() const = 0;
+ virtual MemoryVector<byte> x509_subject_public_key() const = 0;
/**
* Get an X509 decoder that can be used to set the values of this