From a0aa28616cee4d202b7603ade0059cc7193fce3a Mon Sep 17 00:00:00 2001
From: "Raif S. Naffah"
Date: Tue, 7 Feb 2006 12:06:48 +0000
Subject: 2006-02-07 Raif S. Naffah
* gnu/java/security/key/KeyPairCodecFactory.java (getEncodingName): New
method.
(getEncodingShortName): Likewise.
* gnu/java/security/key/IKeyPairCodec.java (X509_FORMAT): New constant.
(PKCS8_FORMAT): Likewise.
(ASN1_FORMAT): Likewise.
* gnu/java/security/key/dss/DSSPublicKey.java (DSSPublicKey(4)): Call
constructor with 5 arguments.
(DSSPublicKey(5)): New constructor.
(valueOf): Handle ASN.1 encoding.
(getEncoded): Likewise.
* gnu/java/security/key/dss/DSSPrivateKey.java (DSSPrivateKey(4)): Call
constructor with 5 arguments.
(DSSPrivateKey(5)): New constructor.
(valueOf): Handle ASN.1 encoding.
(getEncoded): Likewise.
* gnu/java/security/key/dss/DSSKeyPairX509Codec.java: New file.
* gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java: Likewise.
* gnu/java/security/key/dss/DSSKeyPairGenerator.java
(PREFERRED_ENCODING_FORMAT): New constant.
(DEFAULT_ENCODING_FORMAT): Likewise.
(preferredFormat): New field.
(setup): Handle preferred format ID.
(generate): Use new ctors with 5 arguments.
* gnu/java/security/key/dss/DSSKey.java (DSSKey): Now accepts a format
ID as an additional argument.
(defaultFormat): new field.
(getFormat): Returns the preferred format as a short string.
* gnu/java/security/jce/sig/DSSKeyFactory.java: New file.
* gnu/java/security/jce/sig/EncodedKeyFactory.java (engineGetKeySpec):
Likewise
* gnu/java/security/jce/sig/DSSKeyPairGeneratorSpi.java
(initialize(AlgorithmParameterSpec)): Set ASN.1 as the preferred
encoding format.
(initialize(int,boolean,SecureRandom)): Likewise.
* gnu/java/security/der/DERWriter.java (writeBitString): Use
writeLength() instead of write().
return buf.length + 1 instead of buf.length.
---
gnu/java/security/key/dss/DSSKey.java | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
(limited to 'gnu/java/security/key/dss/DSSKey.java')
diff --git a/gnu/java/security/key/dss/DSSKey.java b/gnu/java/security/key/dss/DSSKey.java
index c052d3fde..96d9c6703 100644
--- a/gnu/java/security/key/dss/DSSKey.java
+++ b/gnu/java/security/key/dss/DSSKey.java
@@ -40,6 +40,7 @@ package gnu.java.security.key.dss;
import gnu.java.security.Registry;
import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.key.KeyPairCodecFactory;
import java.math.BigInteger;
import java.security.Key;
@@ -59,13 +60,12 @@ import java.security.spec.DSAParameterSpec;
* the relevant getEncoded() methods of each of the private and
* public keys.
*
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
* @see DSSPrivateKey#getEncoded
* @see DSSPublicKey#getEncoded
*/
public abstract class DSSKey implements Key, DSAKey
{
-
// Constants and variables
// -------------------------------------------------------------------------
@@ -90,20 +90,30 @@ public abstract class DSSKey implements Key, DSAKey
*/
protected final BigInteger g;
+ /**
+ * Identifier of the default encoding format to use when externalizing the
+ * key material.
+ */
+ protected final int defaultFormat;
+
// Constructor(s)
// -------------------------------------------------------------------------
/**
- * Trivial protected constructor.
- *
+ * Trivial protected constructor.
+ *
+ * @param defaultFormat the identifier of the encoding format to use by
+ * default when externalizing the key.
* @param p the DSS parameter p.
* @param q the DSS parameter q.
* @param g the DSS parameter g.
*/
- protected DSSKey(BigInteger p, BigInteger q, BigInteger g)
+ protected DSSKey(int defaultFormat, BigInteger p, BigInteger q, BigInteger g)
{
super();
+ this.defaultFormat = defaultFormat <= 0 ? Registry.RAW_ENCODING_ID
+ : defaultFormat;
this.p = p;
this.q = q;
this.g = g;
@@ -137,7 +147,7 @@ public abstract class DSSKey implements Key, DSAKey
public String getFormat()
{
- return null;
+ return KeyPairCodecFactory.getEncodingShortName(defaultFormat);
}
// Other instance methods --------------------------------------------------
--
cgit v1.2.1