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/KeyPairCodecFactory.java | 61 +++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) (limited to 'gnu/java/security/key/KeyPairCodecFactory.java') diff --git a/gnu/java/security/key/KeyPairCodecFactory.java b/gnu/java/security/key/KeyPairCodecFactory.java index 0bf9e6657..d0cb1ca17 100644 --- a/gnu/java/security/key/KeyPairCodecFactory.java +++ b/gnu/java/security/key/KeyPairCodecFactory.java @@ -55,7 +55,7 @@ import java.security.PublicKey; /** *

A Factory class to instantiate key encoder/decoder instances.

* - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class KeyPairCodecFactory { @@ -229,6 +229,65 @@ public class KeyPairCodecFactory return KeyPairGeneratorFactory.getNames(); } + /** + * Returns the fully qualified name of the designated encoding ID. + * + * @param formatID the unique identifier of the encoding format. + * @return the fully qualified name of the designated format. Returns + * null if no such encoding format is known. + */ + public static final String getEncodingName(int formatID) + { + String result = null; + switch (formatID) + { + case Registry.RAW_ENCODING_ID: + result = Registry.RAW_ENCODING; + break; + case Registry.X509_ENCODING_ID: + result = Registry.X509_ENCODING; + break; + case Registry.PKCS8_ENCODING_ID: + result = Registry.PKCS8_ENCODING; + break; + case Registry.ASN1_ENCODING_ID: + result = Registry.ASN1_ENCODING; + break; + } + + return result; + } + + /** + * Returns the short name of the designated encoding ID. This is used by the + * JCE Adapters. + * + * @param formatID the unique identifier of the encoding format. + * @return the short name of the designated format. Returns null + * if no such encoding format is known. + */ + public static final String getEncodingShortName(int formatID) + { + String result = null; + switch (formatID) + { + case Registry.RAW_ENCODING_ID: + result = Registry.RAW_ENCODING_SHORT_NAME; + break; + case Registry.X509_ENCODING_ID: + result = Registry.X509_ENCODING_SORT_NAME; + break; + case Registry.PKCS8_ENCODING_ID: + result = Registry.PKCS8_ENCODING_SHORT_NAME; + break; + case Registry.ASN1_ENCODING_ID: + result = Registry.ASN1_ENCODING_SHORT_NAME; + break; + } + + return result; + } + private static IKeyPairCodec makeInstance (String clazz) { try -- cgit v1.2.1