summaryrefslogtreecommitdiff
path: root/gnu/java/security/key/KeyPairCodecFactory.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/KeyPairCodecFactory.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/KeyPairCodecFactory.java')
-rw-r--r--gnu/java/security/key/KeyPairCodecFactory.java61
1 files changed, 60 insertions, 1 deletions
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;
/**
* <p>A <i>Factory</i> class to instantiate key encoder/decoder instances.</p>
*
- * @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
+ * <code>null</code> 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 <code>null</code>
+ * 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