summaryrefslogtreecommitdiff
path: root/gnu/java/security/key/dss/DSSKey.java
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-02-07 12:06:48 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-02-07 12:06:48 +0000
commita0aa28616cee4d202b7603ade0059cc7193fce3a (patch)
tree7dce14555730876dcc818d79aa65e1faad762e63 /gnu/java/security/key/dss/DSSKey.java
parentd01ec2b120ea555e66712accd965d544566bed2a (diff)
downloadclasspath-a0aa28616cee4d202b7603ade0059cc7193fce3a.tar.gz
2006-02-07 Raif S. Naffah <raif@swiftdsl.com.au>
* 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.
Diffstat (limited to 'gnu/java/security/key/dss/DSSKey.java')
-rw-r--r--gnu/java/security/key/dss/DSSKey.java22
1 files changed, 16 insertions, 6 deletions
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 <code>getEncoded()</code> methods of each of the private and
* public keys.</p>
*
- * @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)
// -------------------------------------------------------------------------
/**
- * <p>Trivial protected constructor.</p>
- *
+ * Trivial protected constructor.
+ *
+ * @param defaultFormat the identifier of the encoding format to use by
+ * default when externalizing the key.
* @param p the DSS parameter <code>p</code>.
* @param q the DSS parameter <code>q</code>.
* @param g the DSS parameter <code>g</code>.
*/
- 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 --------------------------------------------------