summaryrefslogtreecommitdiffstats
path: root/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java')
-rw-r--r--libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java79
1 files changed, 27 insertions, 52 deletions
diff --git a/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java b/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java
index 88249563341..23244afee8d 100644
--- a/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java
+++ b/libjava/classpath/gnu/javax/crypto/keyring/PrivateKeyEntry.java
@@ -42,12 +42,10 @@ import gnu.java.security.key.IKeyPairCodec;
import gnu.java.security.key.KeyPairCodecFactory;
import gnu.java.security.key.dss.DSSPrivateKey;
import gnu.java.security.key.rsa.GnuRSAPrivateKey;
-
import gnu.javax.crypto.key.GnuSecretKey;
import gnu.javax.crypto.key.dh.GnuDHPrivateKey;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
import java.security.Key;
import java.security.KeyFactory;
@@ -56,25 +54,18 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Date;
/**
- * <p>An immutable class representing a private or secret key entry.</p>
+ * An immutable class representing a private or secret key entry.
*/
-public final class PrivateKeyEntry extends PrimitiveEntry
+public final class PrivateKeyEntry
+ extends PrimitiveEntry
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int TYPE = 7;
-
/** The key. */
private Key key;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Creates a new key entry.</p>
- *
+ * Creates a new key entry.
+ *
* @param key The key.
* @param creationDate The entry creation date.
* @param properties The entry properties.
@@ -83,15 +74,10 @@ public final class PrivateKeyEntry extends PrimitiveEntry
public PrivateKeyEntry(Key key, Date creationDate, Properties properties)
{
super(TYPE, creationDate, properties);
-
if (key == null)
- {
- throw new IllegalArgumentException("no private key");
- }
- if (!(key instanceof PrivateKey) && !(key instanceof GnuSecretKey))
- {
- throw new IllegalArgumentException("not a private or secret key");
- }
+ throw new IllegalArgumentException("no private key");
+ if (! (key instanceof PrivateKey) && ! (key instanceof GnuSecretKey))
+ throw new IllegalArgumentException("not a private or secret key");
this.key = key;
}
@@ -100,18 +86,13 @@ public final class PrivateKeyEntry extends PrimitiveEntry
super(TYPE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static PrivateKeyEntry decode(DataInputStream in) throws IOException
{
PrivateKeyEntry entry = new PrivateKeyEntry();
entry.defaultDecode(in);
String type = entry.properties.get("type");
if (type == null)
- {
- throw new MalformedKeyringException("no key type");
- }
+ throw new MalformedKeyringException("no key type");
if (type.equalsIgnoreCase("RAW-DSS"))
{
IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dss");
@@ -128,18 +109,16 @@ public final class PrivateKeyEntry extends PrimitiveEntry
entry.key = coder.decodePrivateKey(entry.payload);
}
else if (type.equalsIgnoreCase("RAW"))
- {
- entry.key = new GnuSecretKey(entry.payload, null);
- }
+ entry.key = new GnuSecretKey(entry.payload, null);
else if (type.equalsIgnoreCase("PKCS8"))
{
try
{
KeyFactory kf = KeyFactory.getInstance("RSA");
- entry.key = kf.generatePrivate(new PKCS8EncodedKeySpec(
- entry.payload));
+ PKCS8EncodedKeySpec ks = new PKCS8EncodedKeySpec(entry.payload);
+ entry.key = kf.generatePrivate(ks);
}
- catch (Exception x)
+ catch (Exception ignored)
{
}
if (entry.key == null)
@@ -147,32 +126,24 @@ public final class PrivateKeyEntry extends PrimitiveEntry
try
{
KeyFactory kf = KeyFactory.getInstance("DSA");
- entry.key = kf.generatePrivate(new PKCS8EncodedKeySpec(
- entry.payload));
+ PKCS8EncodedKeySpec ks = new PKCS8EncodedKeySpec(entry.payload);
+ entry.key = kf.generatePrivate(ks);
}
- catch (Exception x)
+ catch (Exception ignored)
{
}
if (entry.key == null)
- {
- throw new MalformedKeyringException(
- "could not decode PKCS#8 key");
- }
+ throw new MalformedKeyringException("could not decode PKCS#8 key");
}
}
else
- {
- throw new MalformedKeyringException("unsupported key type " + type);
- }
+ throw new MalformedKeyringException("unsupported key type " + type);
return entry;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns this entry's key.</p>
- *
+ * Returns this entry's key.
+ *
* @return The key.
*/
public Key getKey()
@@ -212,8 +183,12 @@ public final class PrivateKeyEntry extends PrimitiveEntry
payload = key.getEncoded();
}
else
- {
- throw new IllegalArgumentException("unsupported private key");
- }
+ throw new IllegalArgumentException("unsupported private key");
+ }
+
+ public String toString()
+ {
+ return "PrivateKeyEntry{key="
+ + (key == null ? "-" : key.getClass().getName()) + "}";
}
}
OpenPOWER on IntegriCloud