summaryrefslogtreecommitdiff
path: root/gnu/javax/crypto
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-07-01 22:48:38 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-07-01 22:48:38 +0000
commit62f65026d3314142ba01b6c7571a4b10f88268a7 (patch)
tree1b213e15189b8930ff3183758e4a63097da662d8 /gnu/javax/crypto
parent6116fe2306c65520801cd6e1bd6a701267b1c378 (diff)
downloadclasspath-62f65026d3314142ba01b6c7571a4b10f88268a7.tar.gz
2006-07-02 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/javax/crypto/keyring/AuthenticatedEntry.java: Source formatting. * gnu/javax/crypto/keyring/BaseKeyring.java: Likewise. * gnu/javax/crypto/keyring/BinaryDataEntry.java: Likewise. * gnu/javax/crypto/keyring/CertificateEntry.java: Likewise. * gnu/javax/crypto/keyring/CertPathEntry.java: Likewise. * gnu/javax/crypto/keyring/CompressedEntry.java: Likewise. * gnu/javax/crypto/keyring/EncryptedEntry.java: Likewise. * gnu/javax/crypto/keyring/Entry.java: Likewise. * gnu/javax/crypto/keyring/EnvelopeEntry.java: Likewise. * gnu/javax/crypto/keyring/GnuPrivateKeyring.java: Likewise. * gnu/javax/crypto/keyring/GnuPublicKeyring.java: Likewise. * gnu/javax/crypto/keyring/IKeyring.java: Likewise. * gnu/javax/crypto/keyring/IPrivateKeyring.java: Likewise. * gnu/javax/crypto/keyring/IPublicKeyring.java: Likewise. * gnu/javax/crypto/keyring/MalformedKeyringException.java: Likewise. * gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java: Likewise. * gnu/javax/crypto/keyring/MeteredInputStream.java: Likewise. * gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java: Likewise. * gnu/javax/crypto/keyring/PasswordEncryptedEntry.java: Likewise. * gnu/javax/crypto/keyring/PasswordProtectedEntry.java: Likewise. * gnu/javax/crypto/keyring/PrimitiveEntry.java: Likewise. * gnu/javax/crypto/keyring/PrivateKeyEntry.java: Likewise. * gnu/javax/crypto/keyring/Properties.java: Likewise. * gnu/javax/crypto/keyring/PublicKeyEntry.java: Likewise.
Diffstat (limited to 'gnu/javax/crypto')
-rw-r--r--gnu/javax/crypto/keyring/AuthenticatedEntry.java89
-rw-r--r--gnu/javax/crypto/keyring/BaseKeyring.java78
-rw-r--r--gnu/javax/crypto/keyring/BinaryDataEntry.java39
-rw-r--r--gnu/javax/crypto/keyring/CertPathEntry.java28
-rw-r--r--gnu/javax/crypto/keyring/CertificateEntry.java40
-rw-r--r--gnu/javax/crypto/keyring/CompressedEntry.java34
-rw-r--r--gnu/javax/crypto/keyring/EncryptedEntry.java64
-rw-r--r--gnu/javax/crypto/keyring/Entry.java75
-rw-r--r--gnu/javax/crypto/keyring/EnvelopeEntry.java112
-rw-r--r--gnu/javax/crypto/keyring/GnuPrivateKeyring.java42
-rw-r--r--gnu/javax/crypto/keyring/GnuPublicKeyring.java19
-rw-r--r--gnu/javax/crypto/keyring/IKeyring.java102
-rw-r--r--gnu/javax/crypto/keyring/IPrivateKeyring.java76
-rw-r--r--gnu/javax/crypto/keyring/IPublicKeyring.java35
-rw-r--r--gnu/javax/crypto/keyring/MalformedKeyringException.java7
-rw-r--r--gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java41
-rw-r--r--gnu/javax/crypto/keyring/MeteredInputStream.java18
-rw-r--r--gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java79
-rw-r--r--gnu/javax/crypto/keyring/PasswordEncryptedEntry.java89
-rw-r--r--gnu/javax/crypto/keyring/PasswordProtectedEntry.java13
-rw-r--r--gnu/javax/crypto/keyring/PrimitiveEntry.java40
-rw-r--r--gnu/javax/crypto/keyring/PrivateKeyEntry.java26
-rw-r--r--gnu/javax/crypto/keyring/Properties.java68
-rw-r--r--gnu/javax/crypto/keyring/PublicKeyEntry.java45
24 files changed, 390 insertions, 869 deletions
diff --git a/gnu/javax/crypto/keyring/AuthenticatedEntry.java b/gnu/javax/crypto/keyring/AuthenticatedEntry.java
index 42baf3d33..cd2e5868d 100644
--- a/gnu/javax/crypto/keyring/AuthenticatedEntry.java
+++ b/gnu/javax/crypto/keyring/AuthenticatedEntry.java
@@ -53,26 +53,17 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
-public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
- Registry
+public final class AuthenticatedEntry
+ extends MaskableEnvelopeEntry
+ implements Registry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 2;
- // Constructor.
- // ------------------------------------------------------------------------
-
public AuthenticatedEntry(String mac, int macLen, Properties properties)
{
super(TYPE, properties);
-
if (macLen <= 0)
- {
- throw new IllegalArgumentException("invalid mac length");
- }
+ throw new IllegalArgumentException("invalid mac length");
this.properties.put("mac", mac);
this.properties.put("maclen", String.valueOf(macLen));
setMasked(false);
@@ -84,32 +75,22 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
setMasked(true);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static AuthenticatedEntry decode(DataInputStream in)
throws IOException
{
AuthenticatedEntry entry = new AuthenticatedEntry();
entry.properties.decode(in);
- if (!entry.properties.containsKey("mac"))
- {
- throw new MalformedKeyringException("no mac specified");
- }
- if (!entry.properties.containsKey("maclen"))
- {
- throw new MalformedKeyringException("no mac length specified");
- }
+ if (! entry.properties.containsKey("mac"))
+ throw new MalformedKeyringException("no mac specified");
+ if (! entry.properties.containsKey("maclen"))
+ throw new MalformedKeyringException("no mac length specified");
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Computes the mac over this envelope's data. This method <b>must</b> be
* called before this entry in encoded.
- *
+ *
* @param key The key to authenticate with.
* @throws IOException If encoding fails.
* @throws InvalidKeyException If the supplied key is bad.
@@ -117,11 +98,8 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
public void authenticate(byte[] key) throws IOException, InvalidKeyException
{
if (isMasked())
- {
- throw new IllegalStateException("entry is masked");
- }
+ throw new IllegalStateException("entry is masked");
IMac m = getMac(key);
-
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
MacOutputStream macout = new MacOutputStream(bout, m);
DataOutputStream out2 = new DataOutputStream(macout);
@@ -135,36 +113,28 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
}
/**
- * Verifies this entry's payload. This method will unmask this entry,
- * thus it must be called before accessing its contents.
- *
+ * Verifies this entry's payload. This method will unmask this entry, thus it
+ * must be called before accessing its contents.
+ *
* @param key The key to use to authenticate.
* @throws InvalidKeyException If the given key is improper.
*/
public void verify(byte[] key) throws InvalidKeyException
{
- if (!isMasked() || payload == null)
- {
- return;
- }
+ if (! isMasked() || payload == null)
+ return;
IMac m = getMac(key);
-
m.update(payload, 0, payload.length - m.macSize());
byte[] macValue = new byte[m.macSize()];
System.arraycopy(payload, payload.length - macValue.length, macValue, 0,
macValue.length);
- if (!Arrays.equals(macValue, m.digest()))
- {
- throw new IllegalArgumentException("MAC verification failed");
- }
+ if (! Arrays.equals(macValue, m.digest()))
+ throw new IllegalArgumentException("MAC verification failed");
try
{
- DataInputStream in = new DataInputStream(
- new ByteArrayInputStream(
- payload,
- 0,
- payload.length
- - m.macSize()));
+ int len = payload.length - m.macSize();
+ ByteArrayInputStream bais = new ByteArrayInputStream(payload, 0, len);
+ DataInputStream in = new DataInputStream(bais);
decodeEnvelope(in);
}
catch (IOException ioe)
@@ -178,27 +148,17 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
protected void encodePayload() throws IOException
{
if (payload == null)
- {
- throw new IllegalStateException("not authenticated");
- }
+ throw new IllegalStateException("not authenticated");
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private IMac getMac(byte[] key) throws InvalidKeyException
{
IMac mac = MacFactory.getInstance(properties.get("mac"));
if (mac == null)
- {
- throw new IllegalArgumentException("no such mac: "
- + properties.get("mac"));
- }
+ throw new IllegalArgumentException("no such mac: " + properties.get("mac"));
int maclen = 0;
- if (!properties.containsKey("maclen"))
- {
- throw new IllegalArgumentException("no MAC length");
- }
+ if (! properties.containsKey("maclen"))
+ throw new IllegalArgumentException("no MAC length");
try
{
maclen = Integer.parseInt(properties.get("maclen"));
@@ -207,7 +167,6 @@ public final class AuthenticatedEntry extends MaskableEnvelopeEntry implements
{
throw new IllegalArgumentException("bad MAC length");
}
-
HashMap macAttr = new HashMap();
macAttr.put(IMac.MAC_KEY_MATERIAL, key);
macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen));
diff --git a/gnu/javax/crypto/keyring/BaseKeyring.java b/gnu/javax/crypto/keyring/BaseKeyring.java
index 5fe7dbf4d..369507d4c 100644
--- a/gnu/javax/crypto/keyring/BaseKeyring.java
+++ b/gnu/javax/crypto/keyring/BaseKeyring.java
@@ -38,86 +38,58 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
-import java.io.InputStream;
+import gnu.java.security.Registry;
+
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
-
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
-import gnu.java.security.Registry;
-
-public abstract class BaseKeyring implements IKeyring
+public abstract class BaseKeyring
+ implements IKeyring
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
- /**
- * The top-level keyring data.
- */
+ /** The top-level keyring data. */
protected PasswordAuthenticatedEntry keyring;
-
protected CompressedEntry keyring2;
- // Constructors.
- // ------------------------------------------------------------------------
-
public BaseKeyring()
{
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public void load(Map attributes) throws IOException
{
InputStream in = (InputStream) attributes.get(KEYRING_DATA_IN);
if (in == null)
- {
- throw new IllegalArgumentException("no input stream");
- }
+ throw new IllegalArgumentException("no input stream");
char[] password = (char[]) attributes.get(KEYRING_PASSWORD);
if (password == null)
- {
- password = new char[0];
- }
+ password = new char[0];
if (in.read() != Registry.GKR_MAGIC[0]
|| in.read() != Registry.GKR_MAGIC[1]
|| in.read() != Registry.GKR_MAGIC[2]
|| in.read() != Registry.GKR_MAGIC[3])
- {
- throw new MalformedKeyringException("magic");
- }
+ throw new MalformedKeyringException("magic");
load(in, password);
-
List l = keyring.getEntries();
if (l.size() == 1 && (l.get(0) instanceof CompressedEntry))
- {
- keyring2 = (CompressedEntry) l.get(0);
- }
+ keyring2 = (CompressedEntry) l.get(0);
}
public void store(Map attributes) throws IOException
{
OutputStream out = (OutputStream) attributes.get(KEYRING_DATA_OUT);
if (out == null)
- {
- throw new IllegalArgumentException("no output stream");
- }
+ throw new IllegalArgumentException("no output stream");
char[] password = (char[]) attributes.get(KEYRING_PASSWORD);
if (password == null)
- {
- password = new char[0];
- }
+ password = new char[0];
if (keyring == null)
- {
- throw new IllegalStateException("empty keyring");
- }
+ throw new IllegalStateException("empty keyring");
out.write(Registry.GKR_MAGIC);
store(out, password);
@@ -131,45 +103,35 @@ public abstract class BaseKeyring implements IKeyring
public int size()
{
if (keyring == null)
- {
- throw new IllegalStateException ("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return ((StringTokenizer) aliases()).countTokens();
}
public Enumeration aliases()
{
if (keyring == null)
- {
- throw new IllegalStateException ("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return new StringTokenizer(keyring.getAliasList(), ";");
}
public boolean containsAlias(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return keyring.containsAlias(alias);
}
public List get(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
return keyring.get(alias);
}
public void add(Entry entry)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
if (keyring2 != null)
keyring2.add(entry);
else
@@ -179,9 +141,7 @@ public abstract class BaseKeyring implements IKeyring
public void remove(String alias)
{
if (keyring == null)
- {
- throw new IllegalStateException("keyring not loaded");
- }
+ throw new IllegalStateException("keyring not loaded");
keyring.remove(alias);
}
diff --git a/gnu/javax/crypto/keyring/BinaryDataEntry.java b/gnu/javax/crypto/keyring/BinaryDataEntry.java
index 2dcd5454f..e694487e1 100644
--- a/gnu/javax/crypto/keyring/BinaryDataEntry.java
+++ b/gnu/javax/crypto/keyring/BinaryDataEntry.java
@@ -40,29 +40,22 @@ package gnu.javax.crypto.keyring;
import java.io.DataInputStream;
import java.io.IOException;
-
import java.util.Date;
/**
- * A binary data entry is a primitive entry that simply contains some amount
- * of arbitrary binary data and an optional content type.
+ * A binary data entry is a primitive entry that simply contains some amount of
+ * arbitrary binary data and an optional content type.
*/
-public class BinaryDataEntry extends PrimitiveEntry
+public class BinaryDataEntry
+ extends PrimitiveEntry
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 9;
- // Constructors.
- // ------------------------------------------------------------------------
-
/**
* Creates a new binary data entry.
- *
- * @param contentType The content type of this entry. This parameter can
- * be <code>null</code> if no content type is needed.
+ *
+ * @param contentType The content type of this entry. This parameter can be
+ * <code>null</code> if no content type is needed.
* @param data The data.
* @param creationDate The creation date.
* @param properties This entry's properties.
@@ -72,14 +65,10 @@ public class BinaryDataEntry extends PrimitiveEntry
{
super(TYPE, creationDate, properties);
if (data == null)
- {
- throw new IllegalArgumentException("no data");
- }
+ throw new IllegalArgumentException("no data");
payload = (byte[]) data.clone();
if (contentType != null)
- {
- this.properties.put("content-type", contentType);
- }
+ this.properties.put("content-type", contentType);
}
private BinaryDataEntry()
@@ -87,9 +76,6 @@ public class BinaryDataEntry extends PrimitiveEntry
super(TYPE);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static BinaryDataEntry decode(DataInputStream in) throws IOException
{
BinaryDataEntry entry = new BinaryDataEntry();
@@ -97,13 +83,10 @@ public class BinaryDataEntry extends PrimitiveEntry
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns the content type of this entry, or <code>null</code> if this
* property is not set.
- *
+ *
* @return The content type.
*/
public String getContentType()
@@ -113,7 +96,7 @@ public class BinaryDataEntry extends PrimitiveEntry
/**
* Returns this object's data field.
- *
+ *
* @return The data.
*/
public byte[] getData()
diff --git a/gnu/javax/crypto/keyring/CertPathEntry.java b/gnu/javax/crypto/keyring/CertPathEntry.java
index f9e523b2c..32b86084f 100644
--- a/gnu/javax/crypto/keyring/CertPathEntry.java
+++ b/gnu/javax/crypto/keyring/CertPathEntry.java
@@ -50,27 +50,18 @@ import java.util.Date;
/**
* A primitive entry that contains a path of X.509 certificates.
*/
-public final class CertPathEntry extends PrimitiveEntry
+public final class CertPathEntry
+ extends PrimitiveEntry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 8;
-
private Certificate[] path;
- // Constructor.
- // ------------------------------------------------------------------------
-
public CertPathEntry(Certificate[] path, Date creationDate,
Properties properties)
{
super(TYPE, creationDate, properties);
if (path == null || path.length == 0)
- {
- throw new IllegalArgumentException("no certificate path");
- }
+ throw new IllegalArgumentException("no certificate path");
this.path = (Certificate[]) path.clone();
}
@@ -79,9 +70,6 @@ public final class CertPathEntry extends PrimitiveEntry
super(TYPE);
}
- // Class method.
- // ------------------------------------------------------------------------
-
public static CertPathEntry decode(DataInputStream in) throws IOException
{
CertPathEntry entry = new CertPathEntry();
@@ -92,8 +80,7 @@ public final class CertPathEntry extends PrimitiveEntry
try
{
CertificateFactory fact = CertificateFactory.getInstance("X.509");
- entry.path = (Certificate[]) fact.generateCertificates(in2).toArray(
- new Certificate[0]);
+ entry.path = (Certificate[]) fact.generateCertificates(in2).toArray(new Certificate[0]);
}
catch (CertificateException ce)
{
@@ -102,9 +89,6 @@ public final class CertPathEntry extends PrimitiveEntry
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public Certificate[] getCertPath()
{
return path;
@@ -117,9 +101,7 @@ public final class CertPathEntry extends PrimitiveEntry
try
{
for (int i = 0; i < path.length; i++)
- {
- bout.write(path[i].getEncoded());
- }
+ bout.write(path[i].getEncoded());
}
catch (CertificateEncodingException cee)
{
diff --git a/gnu/javax/crypto/keyring/CertificateEntry.java b/gnu/javax/crypto/keyring/CertificateEntry.java
index 67ac7bf4b..661758442 100644
--- a/gnu/javax/crypto/keyring/CertificateEntry.java
+++ b/gnu/javax/crypto/keyring/CertificateEntry.java
@@ -47,40 +47,30 @@ import java.security.cert.CertificateFactory;
import java.util.Date;
/**
- * <p>An immutable class representing a trusted certificate entry.</p>
+ * An immutable class representing a trusted certificate entry.
*/
-public final class CertificateEntry extends PrimitiveEntry
+public final class CertificateEntry
+ extends PrimitiveEntry
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int TYPE = 5;
-
/** The certificate. */
private Certificate certificate;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Creates a new certificate entry.
- *
+ *
* @param certificate The certificate.
* @param creationDate The creation date.
* @param properties The alias.
* @throws IllegalArgumentException If any argument is null, or if the alias
- * is empty.
+ * is empty.
*/
public CertificateEntry(Certificate certificate, Date creationDate,
Properties properties)
{
super(TYPE, creationDate, properties);
-
if (certificate == null)
- {
- throw new IllegalArgumentException("no certificate");
- }
+ throw new IllegalArgumentException("no certificate");
this.certificate = certificate;
this.properties.put("type", certificate.getType());
}
@@ -90,9 +80,6 @@ public final class CertificateEntry extends PrimitiveEntry
super(TYPE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static CertificateEntry decode(DataInputStream in) throws IOException
{
CertificateEntry entry = new CertificateEntry();
@@ -100,9 +87,7 @@ public final class CertificateEntry extends PrimitiveEntry
entry.makeCreationDate();
String type = entry.properties.get("type");
if (type == null)
- {
- throw new MalformedKeyringException("no certificate type");
- }
+ throw new MalformedKeyringException("no certificate type");
int len = in.readInt();
MeteredInputStream in2 = new MeteredInputStream(in, len);
try
@@ -114,19 +99,14 @@ public final class CertificateEntry extends PrimitiveEntry
{
throw new MalformedKeyringException(ce.toString());
}
- if (!in2.limitReached())
- {
- throw new MalformedKeyringException("extra data at end of payload");
- }
+ if (! in2.limitReached())
+ throw new MalformedKeyringException("extra data at end of payload");
return entry;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Returns this entry's certificate.
- *
+ *
* @return The certificate.
*/
public Certificate getCertificate()
diff --git a/gnu/javax/crypto/keyring/CompressedEntry.java b/gnu/javax/crypto/keyring/CompressedEntry.java
index cce930d73..b24c6715a 100644
--- a/gnu/javax/crypto/keyring/CompressedEntry.java
+++ b/gnu/javax/crypto/keyring/CompressedEntry.java
@@ -42,22 +42,15 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-
import java.util.Iterator;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
-public class CompressedEntry extends EnvelopeEntry
+public class CompressedEntry
+ extends EnvelopeEntry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 4;
- // Constructor.
- // ------------------------------------------------------------------------
-
public CompressedEntry(Properties properties)
{
super(TYPE, properties);
@@ -69,24 +62,16 @@ public class CompressedEntry extends EnvelopeEntry
this(new Properties());
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static CompressedEntry decode(DataInputStream in) throws IOException
{
CompressedEntry entry = new CompressedEntry();
entry.properties.decode(in);
String alg = entry.properties.get("algorithm");
if (alg == null)
- {
- throw new MalformedKeyringException("no compression algorithm");
- }
- if (!alg.equalsIgnoreCase("DEFLATE"))
- {
- throw new MalformedKeyringException(
- "unsupported compression algorithm: "
- + alg);
- }
+ throw new MalformedKeyringException("no compression algorithm");
+ if (! alg.equalsIgnoreCase("DEFLATE"))
+ throw new MalformedKeyringException("unsupported compression algorithm: "
+ + alg);
int len = in.readInt();
MeteredInputStream min = new MeteredInputStream(in, len);
InflaterInputStream infin = new InflaterInputStream(min);
@@ -95,18 +80,13 @@ public class CompressedEntry extends EnvelopeEntry
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
protected void encodePayload() throws IOException
{
ByteArrayOutputStream buf = new ByteArrayOutputStream(1024);
DeflaterOutputStream dout = new DeflaterOutputStream(buf);
DataOutputStream out2 = new DataOutputStream(dout);
for (Iterator it = entries.iterator(); it.hasNext();)
- {
- ((Entry) it.next()).encode(out2);
- }
+ ((Entry) it.next()).encode(out2);
dout.finish();
payload = buf.toByteArray();
}
diff --git a/gnu/javax/crypto/keyring/EncryptedEntry.java b/gnu/javax/crypto/keyring/EncryptedEntry.java
index 429e31dd0..f0693cc91 100644
--- a/gnu/javax/crypto/keyring/EncryptedEntry.java
+++ b/gnu/javax/crypto/keyring/EncryptedEntry.java
@@ -58,23 +58,13 @@ import java.util.Iterator;
public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 0;
- // Constructor.
- // ------------------------------------------------------------------------
-
public EncryptedEntry(String cipher, String mode, Properties properties)
{
super(TYPE, properties);
if (cipher == null || mode == null)
- {
- throw new IllegalArgumentException(
- "neither cipher nor mode can be null");
- }
+ throw new IllegalArgumentException("neither cipher nor mode can be null");
properties.put("cipher", cipher);
properties.put("mode", mode);
setMasked(false);
@@ -86,34 +76,22 @@ public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
setMasked(true);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static EncryptedEntry decode(DataInputStream in) throws IOException
{
EncryptedEntry entry = new EncryptedEntry();
entry.defaultDecode(in);
- if (!entry.properties.containsKey("cipher"))
- {
- throw new MalformedKeyringException("no cipher");
- }
- if (!entry.properties.containsKey("cipher"))
- {
- throw new MalformedKeyringException("no cipher");
- }
+ if (! entry.properties.containsKey("cipher"))
+ throw new MalformedKeyringException("no cipher");
+ if (! entry.properties.containsKey("cipher"))
+ throw new MalformedKeyringException("no cipher");
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public void decrypt(byte[] key, byte[] iv) throws IllegalArgumentException,
WrongPaddingException
{
- if (!isMasked() || payload == null)
- {
- return;
- }
+ if (! isMasked() || payload == null)
+ return;
IMode mode = getMode(key, iv, IMode.DECRYPTION);
IPad padding = null;
padding = PadFactory.getInstance("PKCS7");
@@ -126,12 +104,8 @@ public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
count += mode.currentBlockSize();
}
int padlen = padding.unpad(buf, 0, buf.length);
- DataInputStream in = new DataInputStream(
- new ByteArrayInputStream(
- buf,
- 0,
- buf.length
- - padlen));
+ int len = buf.length - padlen;
+ DataInputStream in = new DataInputStream(new ByteArrayInputStream(buf, 0, len));
try
{
decodeEnvelope(in);
@@ -175,22 +149,14 @@ public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
public void encodePayload() throws IOException
{
if (payload == null)
- {
- throw new IOException("not encrypted");
- }
+ throw new IOException("not encrypted");
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private IMode getMode(byte[] key, byte[] iv, int state)
{
IBlockCipher cipher = CipherFactory.getInstance(properties.get("cipher"));
if (cipher == null)
- {
- throw new IllegalArgumentException("no such cipher: "
- + properties.get("cipher"));
- }
+ throw new IllegalArgumentException("no such cipher: " + properties.get("cipher"));
int blockSize = cipher.defaultBlockSize();
if (properties.containsKey("block-size"))
{
@@ -204,13 +170,9 @@ public class EncryptedEntry extends MaskableEnvelopeEntry implements Registry
+ nfe.getMessage());
}
}
- IMode mode = ModeFactory.getInstance(properties.get("mode"), cipher,
- blockSize);
+ IMode mode = ModeFactory.getInstance(properties.get("mode"), cipher, blockSize);
if (mode == null)
- {
- throw new IllegalArgumentException("no such mode: "
- + properties.get("mode"));
- }
+ throw new IllegalArgumentException("no such mode: " + properties.get("mode"));
HashMap modeAttr = new HashMap();
modeAttr.put(IMode.KEY_MATERIAL, key);
diff --git a/gnu/javax/crypto/keyring/Entry.java b/gnu/javax/crypto/keyring/Entry.java
index 5a8431f98..ef225db95 100644
--- a/gnu/javax/crypto/keyring/Entry.java
+++ b/gnu/javax/crypto/keyring/Entry.java
@@ -50,46 +50,39 @@ import java.util.logging.Logger;
*/
public abstract class Entry
{
- // Fields.
- // ------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(Entry.class.getName());
- private static final String[] TYPES = new String[]
- {
- "Encrypted", "PasswordEncrypted", "Authenticated", "PasswordAuthenticated",
- "Compressed", "Certificate", "PublicKey", "PrivateKey", "CertPath",
- "BinaryData"
- };
+ private static final String[] TYPES = new String[] {
+ "Encrypted",
+ "PasswordEncrypted",
+ "Authenticated",
+ "PasswordAuthenticated",
+ "Compressed",
+ "Certificate",
+ "PublicKey",
+ "PrivateKey",
+ "CertPath",
+ "BinaryData" };
/** This entry's type identifier. */
protected int type;
-
/** This entry's property set. */
protected Properties properties;
-
/** This entry's payload. */
protected byte[] payload;
- // Constructor.
- // ------------------------------------------------------------------------
-
/**
* Creates a new Entry.
- *
+ *
* @param type This entry's type.
* @param properties This entry's properties.
- * @throws IllegalArgumentException If the properties argument is null,
- * or if the type is out of range.
+ * @throws IllegalArgumentException If the properties argument is null, or if
+ * the type is out of range.
*/
protected Entry(int type, Properties properties)
{
if (type < 0 || type > 255)
- {
- throw new IllegalArgumentException("invalid packet type");
- }
+ throw new IllegalArgumentException("invalid packet type");
if (properties == null)
- {
- throw new IllegalArgumentException("no properties");
- }
+ throw new IllegalArgumentException("no properties");
this.type = type;
this.properties = (Properties) properties.clone();
}
@@ -100,20 +93,15 @@ public abstract class Entry
protected Entry(final int type)
{
if (type < 0 || type > 255)
- {
- throw new IllegalArgumentException("invalid packet type");
- }
+ throw new IllegalArgumentException("invalid packet type");
this.type = type;
properties = new Properties();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns this entry's properties object. The properties are cloned before
* being returned.
- *
+ *
* @return The properties.
*/
public Properties getProperties()
@@ -132,22 +120,18 @@ public abstract class Entry
}
/**
- * This method is called when this entry needs to be written to an
- * output stream.
- *
+ * This method is called when this entry needs to be written to an output
+ * stream.
+ *
* @param out The stream to write to.
* @throws IOException If an I/O exception occurs.
*/
public void encode(DataOutputStream out) throws IOException
{
if (payload == null)
- {
- encodePayload();
- }
+ encodePayload();
if (out == null)
- {
- return;
- }
+ return;
out.write(type);
properties.encode(out);
out.writeInt(payload.length);
@@ -156,13 +140,13 @@ public abstract class Entry
public String toString()
{
-
return new StringBuilder("Entry{")
.append("type=").append(TYPES[type])
.append(", properties=").append(properties)
.append(", payload=")
- .append(payload == null? "-" : "byte[" + payload.length + "]")
- .append("}").toString();
+ .append(payload == null ? "-" : "byte[" + payload.length + "]")
+ .append( "}")
+ .toString();
}
/**
@@ -178,18 +162,13 @@ public abstract class Entry
properties.decode(in);
int len = in.readInt();
if (len < 0)
- {
- throw new IOException("corrupt length");
- }
+ throw new IOException("corrupt length");
if (Configuration.DEBUG)
log.fine("About to instantiate new payload byte array for " + this);
payload = new byte[len];
in.readFully(payload);
}
- // Abstract methods.
- // ------------------------------------------------------------------------
-
/**
* This method is called of subclasses when the payload data needs to be
* created.
diff --git a/gnu/javax/crypto/keyring/EnvelopeEntry.java b/gnu/javax/crypto/keyring/EnvelopeEntry.java
index 58901475c..fe39091b0 100644
--- a/gnu/javax/crypto/keyring/EnvelopeEntry.java
+++ b/gnu/javax/crypto/keyring/EnvelopeEntry.java
@@ -52,32 +52,24 @@ import java.util.StringTokenizer;
import java.util.logging.Logger;
/**
- * An envelope entry is a generic container for some number of primitive
- * and other envelope entries.
+ * An envelope entry is a generic container for some number of primitive and
+ * other envelope entries.
*/
-public abstract class EnvelopeEntry extends Entry
+public abstract class EnvelopeEntry
+ extends Entry
{
- // Fields.
- // ------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(EnvelopeEntry.class.getName());
/** The envelope that contains this one (if any). */
protected EnvelopeEntry containingEnvelope;
-
/** The contained entries. */
protected List entries;
- // Constructor.
- // ------------------------------------------------------------------------
-
public EnvelopeEntry(int type, Properties properties)
{
super(type, properties);
entries = new LinkedList();
if (this.properties.get("alias-list") != null)
- {
- this.properties.remove("alias-list");
- }
+ this.properties.remove("alias-list");
}
protected EnvelopeEntry(int type)
@@ -86,12 +78,9 @@ public abstract class EnvelopeEntry extends Entry
entries = new LinkedList();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Adds an entry to this envelope.
- *
+ *
* @param entry The entry to add.
*/
public void add(Entry entry)
@@ -102,7 +91,6 @@ public abstract class EnvelopeEntry extends Entry
{
if (entry instanceof EnvelopeEntry)
((EnvelopeEntry) entry).setContainingEnvelope(this);
-
entries.add(entry);
if (Configuration.DEBUG)
log.fine("Payload is " + (payload == null ? "" : "not ") + "null");
@@ -113,12 +101,11 @@ public abstract class EnvelopeEntry extends Entry
}
/**
- * Tests if this envelope contains a primitive entry with the
- * given alias.
- *
+ * Tests if this envelope contains a primitive entry with the given alias.
+ *
* @param alias The alias to test.
- * @return True if this envelope (or one of the contained envelopes)
- * contains a primitive entry with the given alias.
+ * @return True if this envelope (or one of the contained envelopes) contains
+ * a primitive entry with the given alias.
*/
public boolean containsAlias(String alias)
{
@@ -146,34 +133,30 @@ public abstract class EnvelopeEntry extends Entry
/**
* Tests if this envelope contains the given entry.
- *
+ *
* @param entry The entry to test.
* @return True if this envelope contains the given entry.
*/
public boolean containsEntry(Entry entry)
{
if (entry instanceof EnvelopeEntry)
- {
- return entries.contains(entry);
- }
- else if (entry instanceof PrimitiveEntry)
- {
- for (Iterator it = entries.iterator(); it.hasNext();)
- {
- Entry e = (Entry) it.next();
- if (e.equals(entry))
- return true;
- if ((e instanceof EnvelopeEntry)
- && ((EnvelopeEntry) e).containsEntry(entry))
- return true;
- }
- }
+ return entries.contains(entry);
+ if (entry instanceof PrimitiveEntry)
+ for (Iterator it = entries.iterator(); it.hasNext();)
+ {
+ Entry e = (Entry) it.next();
+ if (e.equals(entry))
+ return true;
+ if ((e instanceof EnvelopeEntry)
+ && ((EnvelopeEntry) e).containsEntry(entry))
+ return true;
+ }
return false;
}
/**
* Returns a copy of all entries this envelope contains.
- *
+ *
* @return All contained entries.
*/
public List getEntries()
@@ -182,10 +165,9 @@ public abstract class EnvelopeEntry extends Entry
}
/**
- * Gets all primitive entries that have the given alias. If there
- * are any masked entries that contain the given alias, they will
- * be returned as well.
- *
+ * Gets all primitive entries that have the given alias. If there are any
+ * masked entries that contain the given alias, they will be returned as well.
+ *
* @param alias The alias of the entries to get.
* @return A list of all primitive entries that have the given alias.
*/
@@ -202,7 +184,6 @@ public abstract class EnvelopeEntry extends Entry
EnvelopeEntry ee = (EnvelopeEntry) e;
if (! ee.containsAlias(alias))
continue;
-
if (ee instanceof MaskableEnvelopeEntry)
{
MaskableEnvelopeEntry mee = (MaskableEnvelopeEntry) ee;
@@ -231,27 +212,23 @@ public abstract class EnvelopeEntry extends Entry
}
/**
- * Returns the list of all aliases contained by this envelope,
- * separated by a semicolon (';').
- *
+ * Returns the list of all aliases contained by this envelope, separated by a
+ * semicolon (';').
+ *
* @return The list of aliases.
*/
public String getAliasList()
{
String list = properties.get("alias-list");
if (list == null)
- {
- return "";
- }
+ return "";
else
- {
- return list;
- }
+ return list;
}
/**
* Removes the specified entry.
- *
+ *
* @param entry The entry.
* @return True if an entry was removed.
*/
@@ -352,7 +329,8 @@ public abstract class EnvelopeEntry extends Entry
return new StringBuilder("Envelope{")
.append(super.toString())
.append(", entries=").append(entries)
- .append("}").toString();
+ .append("}")
+ .toString();
}
// Protected methods.
@@ -363,17 +341,13 @@ public abstract class EnvelopeEntry extends Entry
ByteArrayOutputStream bout = new ByteArrayOutputStream(1024);
DataOutputStream out = new DataOutputStream(bout);
for (Iterator it = entries.iterator(); it.hasNext();)
- {
- ((Entry) it.next()).encode(out);
- }
+ ((Entry) it.next()).encode(out);
}
protected void setContainingEnvelope(EnvelopeEntry e)
{
if (containingEnvelope != null)
- {
- throw new IllegalArgumentException("envelopes may not be shared");
- }
+ throw new IllegalArgumentException("envelopes may not be shared");
containingEnvelope = e;
}
@@ -423,9 +397,6 @@ public abstract class EnvelopeEntry extends Entry
}
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private void makeAliasList()
{
if (Configuration.DEBUG)
@@ -444,16 +415,15 @@ public abstract class EnvelopeEntry extends Entry
aliasOrList = ((PrimitiveEntry) entry).getAlias();
else if (Configuration.DEBUG)
log.fine("Entry with no Alias. Ignored: " + entry);
-
if (aliasOrList != null)
{
aliasOrList = aliasOrList.trim();
if (aliasOrList.trim().length() > 0)
- {
- buf.append(aliasOrList);
- if (it.hasNext())
- buf.append(';');
- }
+ {
+ buf.append(aliasOrList);
+ if (it.hasNext())
+ buf.append(';');
+ }
}
}
String aliasList = buf.toString();
diff --git a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
index 8ecedcfb9..2ccdad6b3 100644
--- a/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
+++ b/gnu/javax/crypto/keyring/GnuPrivateKeyring.java
@@ -56,30 +56,21 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
- * <p>.</p>
+ *
*/
-public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
+public class GnuPrivateKeyring
+ extends BaseKeyring
+ implements IPrivateKeyring
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(GnuPrivateKeyring.class.getName());
public static final int USAGE = Registry.GKR_PRIVATE_KEYS
| Registry.GKR_PUBLIC_CREDENTIALS;
-
protected String mac;
-
protected int maclen;
-
protected String cipher;
-
protected String mode;
-
protected int keylen;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public GnuPrivateKeyring(String mac, int maclen, String cipher, String mode,
int keylen)
{
@@ -98,12 +89,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
this("HMAC-SHA-1", 20, "AES", "OFB", 16);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public boolean containsPrivateKey(String alias)
{
if (Configuration.DEBUG)
@@ -156,7 +141,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
log.throwing(this.getClass().getName(), "getPrivateKey", e);
throw new UnrecoverableKeyException("authentication failed");
}
-
PasswordEncryptedEntry e2 = null;
for (Iterator it = e1.getEntries().iterator(); it.hasNext();)
{
@@ -167,7 +151,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
break;
}
}
-
if (e2 != null)
{
try
@@ -179,7 +162,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
log.throwing(this.getClass().getName(), "getPrivateKey", e);
throw new UnrecoverableKeyException("decryption failed");
}
-
for (Iterator it = e2.get(alias).iterator(); it.hasNext();)
{
Entry e = (Entry) it.next();
@@ -222,7 +204,7 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
{
if (Configuration.DEBUG)
log.log(Level.FINE, "Exception while encrypting the key. "
- + "Rethrow as IllegalArgumentException", x);
+ + "Rethrow as IllegalArgumentException", x);
throw new IllegalArgumentException(x.toString());
}
if (Configuration.DEBUG)
@@ -238,15 +220,13 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
{
if (Configuration.DEBUG)
log.log(Level.FINE, "Exception while authenticating the encrypted "
- + "key. Rethrow as IllegalArgumentException", x);
+ + "key. Rethrow as IllegalArgumentException", x);
throw new IllegalArgumentException(x.toString());
}
-
keyring.add(auth);
}
else if (Configuration.DEBUG)
log.fine("Keyring already contains alias: " + alias);
-
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "putPrivateKey");
}
@@ -303,7 +283,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
}
else if (Configuration.DEBUG)
log.fine("Keyring already contains alias: " + alias);
-
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "putPublicKey");
}
@@ -359,7 +338,6 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
}
else if (Configuration.DEBUG)
log.fine("Keyring already contains alias: " + alias);
-
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "putCertPath");
}
@@ -370,12 +348,10 @@ public class GnuPrivateKeyring extends BaseKeyring implements IPrivateKeyring
log.entering(this.getClass().getName(), "load");
if (in.read() != USAGE)
throw new MalformedKeyringException("incompatible keyring usage");
-
if (in.read() != PasswordAuthenticatedEntry.TYPE)
- throw new MalformedKeyringException("expecting password-authenticated entry tag");
-
- keyring = PasswordAuthenticatedEntry.decode(new DataInputStream(in),
- password);
+ throw new MalformedKeyringException(
+ "expecting password-authenticated entry tag");
+ keyring = PasswordAuthenticatedEntry.decode(new DataInputStream(in), password);
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "load");
}
diff --git a/gnu/javax/crypto/keyring/GnuPublicKeyring.java b/gnu/javax/crypto/keyring/GnuPublicKeyring.java
index 4e036ff63..5243919c3 100644
--- a/gnu/javax/crypto/keyring/GnuPublicKeyring.java
+++ b/gnu/javax/crypto/keyring/GnuPublicKeyring.java
@@ -51,17 +51,13 @@ import java.util.Date;
import java.util.Iterator;
import java.util.logging.Logger;
-public class GnuPublicKeyring extends BaseKeyring implements IPublicKeyring
+public class GnuPublicKeyring
+ extends BaseKeyring
+ implements IPublicKeyring
{
- // Fields.
- // ------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(GnuPublicKeyring.class.getName());
public static final int USAGE = Registry.GKR_CERTIFICATES;
- // Constructors.
- // ------------------------------------------------------------------------
-
public GnuPublicKeyring(String mac, int macLen)
{
keyring = new PasswordAuthenticatedEntry(mac, macLen, new Properties());
@@ -73,9 +69,6 @@ public class GnuPublicKeyring extends BaseKeyring implements IPublicKeyring
{
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public boolean containsCertificate(String alias)
{
if (Configuration.DEBUG)
@@ -127,7 +120,6 @@ public class GnuPublicKeyring extends BaseKeyring implements IPublicKeyring
}
else if (Configuration.DEBUG)
log.fine("Keyring already contains alias: " + alias);
-
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "putCertificate");
}
@@ -138,10 +130,9 @@ public class GnuPublicKeyring extends BaseKeyring implements IPublicKeyring
log.entering(this.getClass().getName(), "load");
if (in.read() != USAGE)
throw new MalformedKeyringException("incompatible keyring usage");
-
if (in.read() != PasswordAuthenticatedEntry.TYPE)
- throw new MalformedKeyringException("expecting password-authenticated entry tag");
-
+ throw new MalformedKeyringException(
+ "expecting password-authenticated entry tag");
DataInputStream dis = new DataInputStream(in);
keyring = PasswordAuthenticatedEntry.decode(dis, password);
if (Configuration.DEBUG)
diff --git a/gnu/javax/crypto/keyring/IKeyring.java b/gnu/javax/crypto/keyring/IKeyring.java
index 56f467df2..44d537700 100644
--- a/gnu/javax/crypto/keyring/IKeyring.java
+++ b/gnu/javax/crypto/keyring/IKeyring.java
@@ -44,120 +44,118 @@ import java.util.List;
import java.util.Map;
/**
- * <p>The top-level interface to a <i>keyring:</i> a file that is used to
- * store and protect public and private cryptographic keys.</p>
- *
- * <p>A <i>keyring</i> is modelled as a mapping of one <i>alias</i> to one or
- * more <i>entries</i> (optionally of different types).</p>
- *
- * <p>See also the sub-interfaces {@link IPublicKeyring} and
- * {@link IPrivateKeyring} for special types of <i>keyrings</i> --the difference
- * being in the type of entries they contain.</p>
+ * The top-level interface to a <i>keyring:</i> a file that is used to store
+ * and protect public and private cryptographic keys.
+ * <p>
+ * A <i>keyring</i> is modelled as a mapping of one <i>alias</i> to one or
+ * more <i>entries</i> (optionally of different types).
+ * <p>
+ * See also the sub-interfaces {@link IPublicKeyring} and
+ * {@link IPrivateKeyring} for special types of <i>keyrings</i> --the
+ * difference being in the type of entries they contain.
*/
public interface IKeyring
{
-
/**
- * <p>Property name for the source of data to load the keyring from. The
- * value mapped must be a {@link java.io.InputStream}.</p>
+ * Property name for the source of data to load the keyring from. The value
+ * mapped must be a {@link java.io.InputStream}.
*/
public static final String KEYRING_DATA_IN = "gnu.crypto.keyring.data.in";
/**
- * <p>Property name for the data sink to store the keyring to. The value
- * mapped must be a {@link java.io.OutputStream}.</p>
+ * Property name for the data sink to store the keyring to. The value mapped
+ * must be a {@link java.io.OutputStream}.
*/
public static final String KEYRING_DATA_OUT = "gun.crypto.keyring.data.out";
/**
- * <p>Property name for the keyring's top-level password, used to
- * authenticate and/or transform the store itself. The mapped value must be a
- * char array.</p>
+ * Property name for the keyring's top-level password, used to authenticate
+ * and/or transform the store itself. The mapped value must be a char array.
*/
public static final String KEYRING_PASSWORD = "gnu.crypto.keyring.password";
/**
- * <p>Loads a keyring into memory.</p>
- *
- * <p>What happens to the current contents of this keyring? are the new ones
- * merged with the current ones or do they simply replace them?</p>
- *
+ * Loads a keyring into memory.
+ * <p>
+ * What happens to the current contents of this keyring? are the new ones
+ * merged with the current ones or do they simply replace them?
+ *
* @param attributes The attributes that designate the source where the store
- * is to be loaded from. What happens
+ * is to be loaded from. What happens
* @throws IllegalArgumentException If the attributes are inappropriate.
* @throws IOException If the keyring file cannot be read.
* @throws SecurityException If the given password is incorrect, or if the
- * top-level authentication or decryption fails.
+ * top-level authentication or decryption fails.
*/
void load(Map attributes) throws IOException;
/**
- * <p>Stores the contents of this keyring to persistent storage as specified
- * by the designated <code>attributes</code>.</p>
- *
+ * Stores the contents of this keyring to persistent storage as specified by
+ * the designated <code>attributes</code>.
+ *
* @param attributes the attributes that define where the contents of this
- * keyring will be stored.
+ * keyring will be stored.
* @throws IOException if an exception occurs during the process.
*/
void store(Map attributes) throws IOException;
/**
- * <p>Resets this keyring, clearing all sensitive data. This method always
- * suceeds.</p>
+ * Resets this keyring, clearing all sensitive data. This method always
+ * suceeds.
*/
void reset();
/**
- * <p>Returns the number of entries in this keyring.</p>
- *
+ * Returns the number of entries in this keyring.
+ *
* @return The number of current entries in this keyring.
*/
int size();
/**
- * <p>Returns an {@link Enumeration} of all aliases (instances of
- * {@link String}) in this keyring.</p>
- *
- * @return The enumeration of {@link String}s each representing an
- * <i>alias</i> found in this keyring.
+ * Returns an {@link Enumeration} of all aliases (instances of {@link String})
+ * in this keyring.
+ *
+ * @return The enumeration of {@link String}s each representing an <i>alias</i>
+ * found in this keyring.
*/
Enumeration aliases();
/**
* Tests whether or not this keyring contains the given alias.
- *
+ *
* @param alias The alias to check.
* @return true if this keyring contains the alias.
*/
boolean containsAlias(String alias);
/**
- * <p>Returns a {@link List} of entries (instances of {@link Entry}) for the
+ * Returns a {@link List} of entries (instances of {@link Entry}) for the
* given <code>alias</code>, or <code>null</code> if there no such entry
- * exists.</p>
- *
+ * exists.
+ *
* @param alias The alias of the entry(ies) to return.
* @return A list of all entries (instances of {@link Entry} that have the
- * given <code>alias</code>, or <code>null</code> if no one {@link Entry} can
- * be found with the designated <code>alias</code>.
+ * given <code>alias</code>, or <code>null</code> if no one
+ * {@link Entry} can be found with the designated <code>alias</code>.
*/
List get(String alias);
/**
- * <p>Adds a designated {@link Entry} to this keyring.</p>
- *
- * <p>What happens if there is already an entry with the same alias?</p>
- *
+ * Adds a designated {@link Entry} to this keyring.
+ * <p>
+ * What happens if there is already an entry with the same alias?
+ *
* @param entry The entry to put in this keyring.
*/
void add(Entry entry);
/**
- * <p>Removes an entry with the designated <code>alias</code> from this
- * keyring. Does nothing if there was no such entry.</p>
- *
- * <p>What happens if there are more than one?</p>
- *
+ * Removes an entry with the designated <code>alias</code> from this
+ * keyring. Does nothing if there was no such entry.
+ * <p>
+ * What happens if there are more than one?
+ *
* @param alias The alias of the entry to remove.
*/
void remove(String alias);
diff --git a/gnu/javax/crypto/keyring/IPrivateKeyring.java b/gnu/javax/crypto/keyring/IPrivateKeyring.java
index 66bbd84f5..9e2ceab9b 100644
--- a/gnu/javax/crypto/keyring/IPrivateKeyring.java
+++ b/gnu/javax/crypto/keyring/IPrivateKeyring.java
@@ -44,41 +44,41 @@ import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
/**
- * <p>An interface to private, or "personal", keyrings, which contain private
+ * An interface to private, or "personal", keyrings, which contain private
* credentials. The contract is that each such entry is known by a unique
- * <i>alias</i>.</p>
- *
- * <p>What about public keys? and certificate-path?</p>
+ * <i>alias</i>.
+ * <p>
+ * What about public keys? and certificate-path?
*/
-public interface IPrivateKeyring extends IKeyring
+public interface IPrivateKeyring
+ extends IKeyring
{
-
/**
- * <p>Tests if this keyring contains a private key entry with the given
- * <code>alias</code>.</p>
- *
+ * Tests if this keyring contains a private key entry with the given
+ * <code>alias</code>.
+ *
* @param alias The alias to check.
* @return <code>true</code> if this keyring contains a private key with the
- * given <code>alias</code>; <code>false</code> otherwise.</p>
+ * given <code>alias</code>; <code>false</code> otherwise.
*/
boolean containsPrivateKey(String alias);
/**
- * <p>Returns the private key with the given <code>alias</code>.</p>
- *
+ * Returns the private key with the given <code>alias</code>.
+ *
* @param alias The alias of the private key to find.
* @param password The password of the private key.
* @return The private, or secret, key if one is found; <code>null</code> if
- * none were found.
+ * none were found.
* @throws UnrecoverableKeyException If the private key could not be
- * recovered, possibly due to a bad password.
+ * recovered, possibly due to a bad password.
*/
Key getPrivateKey(String alias, char[] password)
throws UnrecoverableKeyException;
/**
- * <p>Adds a private key to this keyring.</p>
- *
+ * Adds a private key to this keyring.
+ *
* @param alias The alias of the private key.
* @param key The private key.
* @param password The password used to protect this private key.
@@ -86,55 +86,57 @@ public interface IPrivateKeyring extends IKeyring
void putPrivateKey(String alias, Key key, char[] password);
/**
- * <p>Checks if this keyring contains a public key with the given
- * <code>alias</code>.</p>
- *
+ * Checks if this keyring contains a public key with the given
+ * <code>alias</code>.
+ *
* @param alias The alias to test.
- * @return <code>true</code> if this keyring contains a public key entry with
- * the given <code>alias</code>; <code>false</code> otherwise.
+ * @return <code>true</code> if this keyring contains a public key entry
+ * with the given <code>alias</code>; <code>false</code>
+ * otherwise.
*/
boolean containsPublicKey(String alias);
/**
- * <p>Returns the public key with the given <code>alias</code>, or
- * <code>null</code> if there is no such entry.</p>
- *
+ * Returns the public key with the given <code>alias</code>, or
+ * <code>null</code> if there is no such entry.
+ *
* @param alias The alias of the public key to find.
* @return The public key; or <code>null</code> if none were found.
*/
PublicKey getPublicKey(String alias);
/**
- * <p>Sets a public key entry.</p>
- *
+ * Sets a public key entry.
+ *
* @param alias The alias for this public key.
* @param key The public key.
*/
void putPublicKey(String alias, PublicKey key);
/**
- * <p>Checks if this keyring contains a certificate path with the given
- * <code>alias</code>.</p>
- *
+ * Checks if this keyring contains a certificate path with the given
+ * <code>alias</code>.
+ *
* @param alias The alias to check.
- * @return <code>true</code> if this keyring contains a certificate path with
- * the given <code>alias</code>; <code>false</code> otherwise.
+ * @return <code>true</code> if this keyring contains a certificate path
+ * with the given <code>alias</code>; <code>false</code>
+ * otherwise.
*/
boolean containsCertPath(String alias);
/**
- * <p>Returns the certificate path with the given <code>alias</code>, or
- * <code>null</code> if there is no such entry.</p>
- *
+ * Returns the certificate path with the given <code>alias</code>, or
+ * <code>null</code> if there is no such entry.
+ *
* @param alias The alias of the certificate path to find.
* @return The certificate path for the designated <code>alias</code>; or
- * <code>null</code> if none were found.
+ * <code>null</code> if none were found.
*/
Certificate[] getCertPath(String alias);
/**
- * <p>Sets a certificate path entry.</p>
- *
+ * Sets a certificate path entry.
+ *
* @param alias The alias for this certificate path.
* @param path The certificate path.
*/
diff --git a/gnu/javax/crypto/keyring/IPublicKeyring.java b/gnu/javax/crypto/keyring/IPublicKeyring.java
index ccf9ca73b..efe568f18 100644
--- a/gnu/javax/crypto/keyring/IPublicKeyring.java
+++ b/gnu/javax/crypto/keyring/IPublicKeyring.java
@@ -41,39 +41,40 @@ package gnu.javax.crypto.keyring;
import java.security.cert.Certificate;
/**
- * <p>An interface for keyrings that contain trusted (by the owner) public
- * credentials (incl. certificates).</p>
- *
+ * An interface for keyrings that contain trusted (by the owner) public
+ * credentials (incl. certificates).
+ *
* @see IKeyring
*/
-public interface IPublicKeyring extends IKeyring
+public interface IPublicKeyring
+ extends IKeyring
{
-
/**
- * <p>Tests if this keyring contains a certificate entry with the specified
- * <code>alias</code>.</p>
- *
+ * Tests if this keyring contains a certificate entry with the specified
+ * <code>alias</code>.
+ *
* @param alias The alias of the certificate to check.
* @return <code>true</code> if this keyring contains a certificate entry
- * that has the given <code>alias</code>; <code>false</code> otherwise.
+ * that has the given <code>alias</code>; <code>false</code>
+ * otherwise.
*/
boolean containsCertificate(String alias);
/**
- * <p>Returns a certificate that has the given <code>alias</code>, or
- * <code>null</code> if this keyring has no such entry.</p>
- *
+ * Returns a certificate that has the given <code>alias</code>, or
+ * <code>null</code> if this keyring has no such entry.
+ *
* @param alias The alias of the certificate to find.
* @return The certificate with the designated <code>alias</code>, or
- * <code>null</code> if none found.
+ * <code>null</code> if none found.
*/
Certificate getCertificate(String alias);
/**
- * <p>Adds a certificate in this keyring, with the given <code>alias</code>.</p>
- *
- * <p>What happens if there is already a certificate entry with this alias?</p>
- *
+ * Adds a certificate in this keyring, with the given <code>alias</code>.
+ * <p>
+ * What happens if there is already a certificate entry with this alias?
+ *
* @param alias The alias of this certificate entry.
* @param cert The certificate.
*/
diff --git a/gnu/javax/crypto/keyring/MalformedKeyringException.java b/gnu/javax/crypto/keyring/MalformedKeyringException.java
index 44c953946..0dab3a764 100644
--- a/gnu/javax/crypto/keyring/MalformedKeyringException.java
+++ b/gnu/javax/crypto/keyring/MalformedKeyringException.java
@@ -40,12 +40,9 @@ package gnu.javax.crypto.keyring;
import java.io.IOException;
-public class MalformedKeyringException extends IOException
+public class MalformedKeyringException
+ extends IOException
{
-
- // Constructors.
- // ------------------------------------------------------------------------
-
public MalformedKeyringException()
{
super();
diff --git a/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java b/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java
index 653d62ced..5206a5e07 100644
--- a/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java
+++ b/gnu/javax/crypto/keyring/MaskableEnvelopeEntry.java
@@ -43,20 +43,15 @@ import java.util.List;
/**
* An envelope entry that can be "masked" -- placed in a state where the
- * envelope's contents cannot be accessed, due to the envelope not being
- * fully decoded, for example.
+ * envelope's contents cannot be accessed, due to the envelope not being fully
+ * decoded, for example.
*/
-public abstract class MaskableEnvelopeEntry extends EnvelopeEntry
+public abstract class MaskableEnvelopeEntry
+ extends EnvelopeEntry
{
- // Fields.
- // ------------------------------------------------------------------------
-
/** The masked state. */
protected boolean masked;
- // Constructors.
- // ------------------------------------------------------------------------
-
public MaskableEnvelopeEntry(int type, Properties properties)
{
super(type, properties);
@@ -67,12 +62,9 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry
super(type);
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Sets the masked state to the specified value.
- *
+ *
* @param masked The new masked state.
*/
protected final void setMasked(boolean masked)
@@ -83,7 +75,7 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry
/**
* Gets the masked state of this object. Certain operations on this object
* will fail if it is masked.
- *
+ *
* @return The current masked state.
*/
public boolean isMasked()
@@ -94,45 +86,35 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry
public void add(Entry entry)
{
if (isMasked())
- {
- throw new IllegalStateException("masked envelope");
- }
+ throw new IllegalStateException("masked envelope");
super.add(entry);
}
public boolean containsEntry(Entry entry)
{
if (isMasked())
- {
- throw new IllegalStateException("masked envelope");
- }
+ throw new IllegalStateException("masked envelope");
return super.containsEntry(entry);
}
public List getEntries()
{
if (isMasked())
- {
- throw new IllegalStateException("masked envelope");
- }
+ throw new IllegalStateException("masked envelope");
return new ArrayList(entries);
}
public List get(String alias)
{
if (isMasked())
- {
- throw new IllegalStateException("masked envelope");
- }
+ throw new IllegalStateException("masked envelope");
return super.get(alias);
}
public boolean remove(Entry entry)
{
if (isMasked())
- {
- throw new IllegalStateException("masked envelope");
- }
+ throw new IllegalStateException("masked envelope");
return super.remove(entry);
}
@@ -140,7 +122,6 @@ public abstract class MaskableEnvelopeEntry extends EnvelopeEntry
{
if (isMasked())
throw new IllegalStateException("masked envelope");
-
return super.remove(alias);
}
diff --git a/gnu/javax/crypto/keyring/MeteredInputStream.java b/gnu/javax/crypto/keyring/MeteredInputStream.java
index fcf2be746..330e4b20f 100644
--- a/gnu/javax/crypto/keyring/MeteredInputStream.java
+++ b/gnu/javax/crypto/keyring/MeteredInputStream.java
@@ -39,22 +39,15 @@ exception statement from your version. */
package gnu.javax.crypto.keyring;
import java.io.FilterInputStream;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
-final class MeteredInputStream extends FilterInputStream
+final class MeteredInputStream
+ extends FilterInputStream
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
private int count;
-
private final int limit;
- // Constructor.
- // ------------------------------------------------------------------------
-
MeteredInputStream(InputStream in, int limit)
{
super(in);
@@ -64,12 +57,9 @@ final class MeteredInputStream extends FilterInputStream
count = 0;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Tests if the number of bytes read has reached the limit.
- *
+ *
* @return True if the limit has been reached.
*/
public boolean limitReached()
diff --git a/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java b/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
index e7c1428a4..be10029c8 100644
--- a/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordAuthenticatedEntry.java
@@ -63,29 +63,21 @@ import java.util.Iterator;
import java.util.logging.Logger;
/**
- * <p>An entry authenticated with a password-based MAC.</p>
+ * An entry authenticated with a password-based MAC.
*/
-public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
+public final class PasswordAuthenticatedEntry
+ extends MaskableEnvelopeEntry
implements PasswordProtectedEntry, Registry
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(PasswordAuthenticatedEntry.class.getName());
public static final int TYPE = 3;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public PasswordAuthenticatedEntry(String mac, int maclen,
Properties properties)
{
super(TYPE, properties);
-
if (mac == null || mac.length() == 0)
- {
- throw new IllegalArgumentException("no MAC specified");
- }
+ throw new IllegalArgumentException("no MAC specified");
this.properties.put("mac", mac);
this.properties.put("maclen", String.valueOf(maclen));
setMasked(false);
@@ -97,9 +89,6 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
setMasked(true);
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static PasswordAuthenticatedEntry decode(DataInputStream in,
char[] password)
throws IOException
@@ -115,10 +104,8 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
entry.decodeEnvelope(in2);
byte[] macValue = new byte[mac.macSize()];
in.readFully(macValue);
- if (!Arrays.equals(macValue, mac.digest()))
- {
- throw new MalformedKeyringException("MAC verification failed");
- }
+ if (! Arrays.equals(macValue, mac.digest()))
+ throw new MalformedKeyringException("MAC verification failed");
return entry;
}
@@ -127,24 +114,15 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
PasswordAuthenticatedEntry entry = new PasswordAuthenticatedEntry();
entry.defaultDecode(in);
- if (!entry.properties.containsKey("mac"))
- {
- throw new MalformedKeyringException("no MAC");
- }
- if (!entry.properties.containsKey("maclen"))
- {
- throw new MalformedKeyringException("no MAC length");
- }
- if (!entry.properties.containsKey("salt"))
- {
- throw new MalformedKeyringException("no salt");
- }
+ if (! entry.properties.containsKey("mac"))
+ throw new MalformedKeyringException("no MAC");
+ if (! entry.properties.containsKey("maclen"))
+ throw new MalformedKeyringException("no MAC length");
+ if (! entry.properties.containsKey("salt"))
+ throw new MalformedKeyringException("no salt");
return entry;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public void verify(char[] password)
{
if (Configuration.DEBUG)
@@ -153,7 +131,7 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
if (Configuration.DEBUG)
log.fine("payload to verify: " + Util.dumpString(payload));
- long tt = - System.currentTimeMillis();
+ long tt = -System.currentTimeMillis();
IMac m = null;
try
{
@@ -163,17 +141,14 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
throw new IllegalArgumentException(x.toString(), x);
}
-
int limit = payload.length - m.macSize();
m.update(payload, 0, limit);
byte[] macValue = new byte[m.macSize()];
- System.arraycopy(payload, payload.length - macValue.length, macValue, 0,
- macValue.length);
+ System.arraycopy(payload, payload.length - macValue.length, macValue,
+ 0, macValue.length);
if (! Arrays.equals(macValue, m.digest()))
throw new IllegalArgumentException("MAC verification failed");
-
setMasked(false);
-
ByteArrayInputStream bais;
try
{
@@ -185,14 +160,13 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
throw new IllegalArgumentException("malformed keyring fragment");
}
-
tt += System.currentTimeMillis();
if (Configuration.DEBUG)
log.fine("Verified in " + tt + "ms.");
}
else if (Configuration.DEBUG)
- log.fine("Skip verification; " + (isMasked() ? "null payload" : "unmasked"));
-
+ log.fine("Skip verification; "
+ + (isMasked() ? "null payload" : "unmasked"));
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "verify");
}
@@ -201,12 +175,10 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "authenticate");
- long tt = - System.currentTimeMillis();
- long t1 = - System.currentTimeMillis();
-
+ long tt = -System.currentTimeMillis();
+ long t1 = -System.currentTimeMillis();
if (isMasked())
throw new IllegalStateException("entry is masked");
-
byte[] salt = new byte[8];
PRNG.getInstance().nextBytes(salt);
t1 += System.currentTimeMillis();
@@ -222,19 +194,17 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
Entry entry = (Entry) it.next();
if (Configuration.DEBUG)
log.fine("-- About to authenticate one " + entry);
- t1 = - System.currentTimeMillis();
+ t1 = -System.currentTimeMillis();
entry.encode(out2);
t1 += System.currentTimeMillis();
if (Configuration.DEBUG)
log.fine("-- Authenticated an Entry in " + t1 + "ms.");
}
bout.write(m.digest());
-
payload = bout.toByteArray();
if (Configuration.DEBUG)
log.fine("authenticated payload: " + Util.dumpString(payload));
setMasked(true);
-
tt += System.currentTimeMillis();
if (Configuration.DEBUG)
{
@@ -258,9 +228,6 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
}
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private IMac getMac(char[] password) throws MalformedKeyringException
{
if (Configuration.DEBUG)
@@ -268,17 +235,14 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
String saltString = properties.get("salt");
if (saltString == null)
throw new MalformedKeyringException("no salt");
-
byte[] salt = Util.toBytesFromString(saltString);
String macAlgorithm = properties.get("mac");
IMac mac = MacFactory.getInstance(macAlgorithm);
if (mac == null)
throw new MalformedKeyringException("no such mac: " + macAlgorithm);
-
String macLenString = properties.get("maclen");
if (macLenString == null)
throw new MalformedKeyringException("no MAC length");
-
int maclen;
try
{
@@ -288,14 +252,12 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
throw new MalformedKeyringException("bad MAC length");
}
-
HashMap pbAttr = new HashMap();
pbAttr.put(IPBE.PASSWORD, password);
pbAttr.put(IPBE.SALT, salt);
pbAttr.put(IPBE.ITERATION_COUNT, ITERATION_COUNT);
IRandom kdf = PRNGFactory.getInstance("PBKDF2-HMAC-SHA");
kdf.init(pbAttr);
-
int keylen = mac.macSize();
byte[] dk = new byte[keylen];
try
@@ -306,7 +268,6 @@ public final class PasswordAuthenticatedEntry extends MaskableEnvelopeEntry
{
throw new Error(shouldNotHappen.toString());
}
-
HashMap macAttr = new HashMap();
macAttr.put(IMac.MAC_KEY_MATERIAL, dk);
macAttr.put(IMac.TRUNCATED_SIZE, Integer.valueOf(maclen));
diff --git a/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java b/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
index 5670f3ed4..00031cbf1 100644
--- a/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordEncryptedEntry.java
@@ -67,27 +67,20 @@ import java.util.logging.Logger;
/**
* An envelope that is encrypted with a password-derived key.
*/
-public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
- PasswordProtectedEntry, Registry
+public class PasswordEncryptedEntry
+ extends MaskableEnvelopeEntry
+ implements PasswordProtectedEntry, Registry
{
- // Constants and fields.
- // ------------------------------------------------------------------------
-
private static final Logger log = Logger.getLogger(PasswordEncryptedEntry.class.getName());
public static final int TYPE = 1;
- // Constructors.
- // ------------------------------------------------------------------------
-
public PasswordEncryptedEntry(String cipher, String mode, int keylen,
Properties properties)
{
super(TYPE, properties);
if ((cipher == null || cipher.length() == 0)
|| (mode == null || mode.length() == 0))
- {
- throw new IllegalArgumentException("cipher nor mode can be empty");
- }
+ throw new IllegalArgumentException("cipher nor mode can be empty");
this.properties.put("cipher", cipher);
this.properties.put("mode", mode);
this.properties.put("keylen", String.valueOf(keylen));
@@ -100,9 +93,6 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
setMasked(true);
}
- // Class methods.
- // ------------------------------------------------------------------------
-
public static PasswordEncryptedEntry decode(DataInputStream in,
char[] password)
throws IOException
@@ -127,9 +117,6 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
public void decrypt(char[] password) throws IllegalArgumentException,
WrongPaddingException
{
@@ -137,7 +124,7 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
log.entering(this.getClass().getName(), "decrypt");
if (isMasked() && payload != null)
{
- long tt = - System.currentTimeMillis();
+ long tt = -System.currentTimeMillis();
IMode mode = getMode(password, IMode.DECRYPTION);
IPad padding = PadFactory.getInstance("PKCS7");
padding.init(mode.currentBlockSize());
@@ -149,11 +136,9 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
count += mode.currentBlockSize();
}
int padlen = padding.unpad(buf, 0, buf.length);
-
setMasked(false);
-
- ByteArrayInputStream baos = new ByteArrayInputStream(buf, 0,
- buf.length - padlen);
+ int len = buf.length - padlen;
+ ByteArrayInputStream baos = new ByteArrayInputStream(buf, 0, len);
DataInputStream in = new DataInputStream(baos);
try
{
@@ -168,7 +153,6 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
}
else if (Configuration.DEBUG)
log.fine("Skip decryption; " + (isMasked() ? "null payload" : "unmasked"));
-
if (Configuration.DEBUG)
log.exiting(this.getClass().getName(), "decrypt");
}
@@ -177,9 +161,8 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
{
if (Configuration.DEBUG)
log.entering(this.getClass().getName(), "encrypt", String.valueOf(password));
- long tt = - System.currentTimeMillis();
- long t1 = - System.currentTimeMillis();
-
+ long tt = -System.currentTimeMillis();
+ long t1 = -System.currentTimeMillis();
byte[] salt = new byte[8];
PRNG.getInstance().nextBytes(salt);
t1 += System.currentTimeMillis();
@@ -196,7 +179,7 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
Entry entry = (Entry) it.next();
if (Configuration.DEBUG)
log.fine("-- About to encode one " + entry);
- t1 = - System.currentTimeMillis();
+ t1 = -System.currentTimeMillis();
entry.encode(out2);
t1 += System.currentTimeMillis();
if (Configuration.DEBUG)
@@ -216,9 +199,7 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
count += mode.currentBlockSize();
}
mode.update(lastBlock, 0, payload, count);
-
setMasked(true);
-
tt += System.currentTimeMillis();
if (Configuration.DEBUG)
{
@@ -243,56 +224,40 @@ public class PasswordEncryptedEntry extends MaskableEnvelopeEntry implements
}
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private IMode getMode(char[] password, int state)
{
String s = properties.get("salt");
if (s == null)
- {
- throw new IllegalArgumentException("no salt");
- }
+ throw new IllegalArgumentException("no salt");
byte[] salt = Util.toBytesFromString(s);
IBlockCipher cipher = CipherFactory.getInstance(properties.get("cipher"));
if (cipher == null)
- {
- throw new IllegalArgumentException("no such cipher: "
- + properties.get("cipher"));
- }
+ throw new IllegalArgumentException("no such cipher: "
+ + properties.get("cipher"));
int blockSize = cipher.defaultBlockSize();
if (properties.containsKey("block-size"))
- {
- try
- {
- blockSize = Integer.parseInt(properties.get("block-size"));
- }
- catch (NumberFormatException nfe)
- {
- throw new IllegalArgumentException("bad block size: "
- + nfe.getMessage());
- }
- }
- IMode mode = ModeFactory.getInstance(properties.get("mode"), cipher,
- blockSize);
+ try
+ {
+ blockSize = Integer.parseInt(properties.get("block-size"));
+ }
+ catch (NumberFormatException nfe)
+ {
+ throw new IllegalArgumentException("bad block size: "
+ + nfe.getMessage());
+ }
+ String modeName = properties.get("mode");
+ IMode mode = ModeFactory.getInstance(modeName, cipher, blockSize);
if (mode == null)
- {
- throw new IllegalArgumentException("no such mode: "
- + properties.get("mode"));
- }
-
+ throw new IllegalArgumentException("no such mode: " + modeName);
HashMap pbAttr = new HashMap();
pbAttr.put(IPBE.PASSWORD, password);
pbAttr.put(IPBE.SALT, salt);
pbAttr.put(IPBE.ITERATION_COUNT, ITERATION_COUNT);
IRandom kdf = PRNGFactory.getInstance("PBKDF2-HMAC-SHA");
kdf.init(pbAttr);
-
int keylen = 0;
- if (!properties.containsKey("keylen"))
- {
- throw new IllegalArgumentException("no key length");
- }
+ if (! properties.containsKey("keylen"))
+ throw new IllegalArgumentException("no key length");
try
{
keylen = Integer.parseInt(properties.get("keylen"));
diff --git a/gnu/javax/crypto/keyring/PasswordProtectedEntry.java b/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
index d5e1df900..5eff63792 100644
--- a/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
+++ b/gnu/javax/crypto/keyring/PasswordProtectedEntry.java
@@ -43,21 +43,12 @@ import java.io.IOException;
public interface PasswordProtectedEntry
{
-
- // Constant.
- // ------------------------------------------------------------------------
-
- /**
- * The iteration count for password-based KDFs.
- */
+ /** The iteration count for password-based KDFs. */
Integer ITERATION_COUNT = Integer.valueOf(1000);
- // Method.
- // ------------------------------------------------------------------------
-
/**
* Encodes this entry, protected by a password.
- *
+ *
* @param out The output stream to encode to.
* @param password The password.
* @throws IOException If an I/O error occurs.
diff --git a/gnu/javax/crypto/keyring/PrimitiveEntry.java b/gnu/javax/crypto/keyring/PrimitiveEntry.java
index f5e63e996..194fe9eee 100644
--- a/gnu/javax/crypto/keyring/PrimitiveEntry.java
+++ b/gnu/javax/crypto/keyring/PrimitiveEntry.java
@@ -43,35 +43,24 @@ import java.util.Date;
/**
* A primitive entry is an entry that contains a single cryptographic entity.
*/
-public abstract class PrimitiveEntry extends Entry
+public abstract class PrimitiveEntry
+ extends Entry
{
-
- // Fields.
- // ------------------------------------------------------------------------
-
/** The creation date. */
protected Date creationDate;
- // Constructor.
- // ------------------------------------------------------------------------
-
protected PrimitiveEntry(int type, Date creationDate, Properties properties)
{
super(type, properties);
if (creationDate == null)
- {
- this.creationDate = new Date();
- }
+ this.creationDate = new Date();
else
- {
- this.creationDate = (Date) creationDate.clone();
- }
- if (!this.properties.containsKey("alias")
+ this.creationDate = (Date) creationDate.clone();
+ if (! this.properties.containsKey("alias")
|| this.properties.get("alias").length() == 0)
- {
- throw new IllegalArgumentException("primitive entries MUST have an alias");
- }
- this.properties.put("creation-date", String.valueOf(this.creationDate.getTime()));
+ throw new IllegalArgumentException("primitive entries MUST have an alias");
+ this.properties.put("creation-date",
+ String.valueOf(this.creationDate.getTime()));
}
protected PrimitiveEntry(int type)
@@ -79,12 +68,9 @@ public abstract class PrimitiveEntry extends Entry
super(type);
}
- // Instance method.
- // ------------------------------------------------------------------------
-
/**
* Returns the alias of this primitive entry.
- *
+ *
* @return The alias.
*/
public String getAlias()
@@ -94,7 +80,7 @@ public abstract class PrimitiveEntry extends Entry
/**
* Returns the creation date of this primitive entry.
- *
+ *
* @return The creation date.
*/
public Date getCreationDate()
@@ -104,7 +90,7 @@ public abstract class PrimitiveEntry extends Entry
public boolean equals(Object object)
{
- if (!getClass().equals(object.getClass()))
+ if (! getClass().equals(object.getClass()))
return false;
return getAlias().equals(((PrimitiveEntry) object).getAlias());
}
@@ -113,9 +99,7 @@ public abstract class PrimitiveEntry extends Entry
{
String s = properties.get("creation-date");
if (s == null)
- {
- throw new MalformedKeyringException("no creation date");
- }
+ throw new MalformedKeyringException("no creation date");
try
{
creationDate = new Date(Long.parseLong(s));
diff --git a/gnu/javax/crypto/keyring/PrivateKeyEntry.java b/gnu/javax/crypto/keyring/PrivateKeyEntry.java
index cf5b41287..23244afee 100644
--- a/gnu/javax/crypto/keyring/PrivateKeyEntry.java
+++ b/gnu/javax/crypto/keyring/PrivateKeyEntry.java
@@ -59,20 +59,13 @@ import java.util.Date;
public final class PrivateKeyEntry
extends PrimitiveEntry
{
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int TYPE = 7;
-
/** The key. */
private Key key;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Creates a new key entry.
- *
+ *
* @param key The key.
* @param creationDate The entry creation date.
* @param properties The entry properties.
@@ -81,13 +74,10 @@ public final class PrivateKeyEntry
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");
-
this.key = key;
}
@@ -96,9 +86,6 @@ public final class PrivateKeyEntry
super(TYPE);
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static PrivateKeyEntry decode(DataInputStream in) throws IOException
{
PrivateKeyEntry entry = new PrivateKeyEntry();
@@ -106,7 +93,6 @@ public final class PrivateKeyEntry
String type = entry.properties.get("type");
if (type == null)
throw new MalformedKeyringException("no key type");
-
if (type.equalsIgnoreCase("RAW-DSS"))
{
IKeyPairCodec coder = KeyPairCodecFactory.getInstance("dss");
@@ -135,7 +121,6 @@ public final class PrivateKeyEntry
catch (Exception ignored)
{
}
-
if (entry.key == null)
{
try
@@ -147,23 +132,18 @@ public final class PrivateKeyEntry
catch (Exception ignored)
{
}
-
if (entry.key == null)
throw new MalformedKeyringException("could not decode PKCS#8 key");
}
}
else
throw new MalformedKeyringException("unsupported key type " + type);
-
return entry;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
* Returns this entry's key.
- *
+ *
* @return The key.
*/
public Key getKey()
@@ -209,6 +189,6 @@ public final class PrivateKeyEntry
public String toString()
{
return "PrivateKeyEntry{key="
- + (key == null ? "-" : key.getClass().getName()) + "}";
+ + (key == null ? "-" : key.getClass().getName()) + "}";
}
}
diff --git a/gnu/javax/crypto/keyring/Properties.java b/gnu/javax/crypto/keyring/Properties.java
index 646b5711d..b833a74ae 100644
--- a/gnu/javax/crypto/keyring/Properties.java
+++ b/gnu/javax/crypto/keyring/Properties.java
@@ -42,27 +42,20 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
-
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* A set of <code>(name =&gt; value)</code> pairs used in keyring entries.
- * Keys and values are simple strings, with the key never being empty and
- * always treated case-insensitively.
+ * Keys and values are simple strings, with the key never being empty and always
+ * treated case-insensitively.
*/
-public class Properties implements Cloneable
+public class Properties
+ implements Cloneable
{
-
- // Field.
- // ------------------------------------------------------------------------
-
private HashMap props;
- // Constructor.
- // ------------------------------------------------------------------------
-
/**
* Creates a new properties object.
*/
@@ -71,9 +64,6 @@ public class Properties implements Cloneable
props = new HashMap();
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Removes all properties from this object.
*/
@@ -84,7 +74,7 @@ public class Properties implements Cloneable
/**
* Creates a copy of this properties object.
- *
+ *
* @return The copy.
*/
public Object clone()
@@ -96,86 +86,75 @@ public class Properties implements Cloneable
/**
* Tests if this object contains a given property name.
- *
+ *
* @param key The key to test.
* @return True if this object contains the given key.
*/
public boolean containsKey(String key)
{
if (key == null || key.length() == 0)
- {
- return false;
- }
+ return false;
return props.containsKey(canonicalize(key));
}
/**
* Tests if this object contains a given property value.
- *
+ *
* @param value The value to test.
* @return True if this object contains the given value.
*/
public boolean containsValue(String value)
{
if (value == null)
- {
- return false;
- }
+ return false;
return props.containsValue(value);
}
/**
* Adds a new property to this object.
- *
+ *
* @param key The key, which can neither be null nor empty.
* @param value The value, which cannot be null.
* @return The old value mapped by the key, if any.
- * @throws IllegalArgumentException If either the key or value parameter
-
- * is null, or if the key is empty.
+ * @throws IllegalArgumentException If either the key or value parameter is
+ * null, or if the key is empty.
*/
public String put(String key, String value)
{
if (key == null || value == null || key.length() == 0)
- {
- throw new IllegalArgumentException("key nor value can be null");
- }
+ throw new IllegalArgumentException("key nor value can be null");
return (String) props.put(canonicalize(key), value);
}
/**
- * Returns the value mapped by the given key, or null if there is no
- * such mapping.
- *
+ * Returns the value mapped by the given key, or null if there is no such
+ * mapping.
+ *
* @param key
*/
public String get(String key)
{
if (key == null || key.length() == 0)
- {
- return null;
- }
+ return null;
return (String) props.get(canonicalize(key));
}
/**
* Removes a key and its value from this object.
- *
+ *
* @param key The key of the property to remove.
* @return The old value mapped by the key, if any.
*/
public String remove(String key)
{
if (key == null || key.length() == 0)
- {
- return null;
- }
+ return null;
return (String) props.remove(canonicalize(key));
}
/**
* Decodes a set of properties from the given input stream.
- *
+ *
* @param in The input stream.
* @throws IOException If an I/O error occurs.
*/
@@ -184,7 +163,7 @@ public class Properties implements Cloneable
int len = in.readInt();
MeteredInputStream min = new MeteredInputStream(in, len);
DataInputStream in2 = new DataInputStream(min);
- while (!min.limitReached())
+ while (! min.limitReached())
{
String name = in2.readUTF();
String value = in2.readUTF();
@@ -194,7 +173,7 @@ public class Properties implements Cloneable
/**
* Encodes this set of properties to the given output stream.
- *
+ *
* @param out The output stream to encode to.
* @throws IOException If an I/O error occurs.
*/
@@ -217,9 +196,6 @@ public class Properties implements Cloneable
return props.toString();
}
- // Own methods.
- // ------------------------------------------------------------------------
-
private String canonicalize(String key)
{
return key.toLowerCase();
diff --git a/gnu/javax/crypto/keyring/PublicKeyEntry.java b/gnu/javax/crypto/keyring/PublicKeyEntry.java
index bc09445fd..3e7f54d3e 100644
--- a/gnu/javax/crypto/keyring/PublicKeyEntry.java
+++ b/gnu/javax/crypto/keyring/PublicKeyEntry.java
@@ -51,27 +51,17 @@ import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.Date;
-public final class PublicKeyEntry extends PrimitiveEntry
+public final class PublicKeyEntry
+ extends PrimitiveEntry
{
-
- // Constants and fields.
- // ------------------------------------------------------------------------
-
public static final int TYPE = 6;
-
private PublicKey key;
- // Constructor.
- // ------------------------------------------------------------------------
-
public PublicKeyEntry(PublicKey key, Date creationDate, Properties properties)
{
super(TYPE, creationDate, properties);
-
if (key == null)
- {
- throw new IllegalArgumentException("no key specified");
- }
+ throw new IllegalArgumentException("no key specified");
this.key = key;
}
@@ -80,18 +70,13 @@ public final class PublicKeyEntry extends PrimitiveEntry
super(TYPE);
}
- // Class method.
- // ------------------------------------------------------------------------
-
public static PublicKeyEntry decode(DataInputStream in) throws IOException
{
PublicKeyEntry entry = new PublicKeyEntry();
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");
@@ -122,33 +107,23 @@ public final class PublicKeyEntry extends PrimitiveEntry
try
{
KeyFactory kf = KeyFactory.getInstance("DSA");
- entry.key = kf.generatePublic(new X509EncodedKeySpec(
- entry.payload));
+ entry.key = kf.generatePublic(new X509EncodedKeySpec(entry.payload));
}
catch (Exception x)
{
}
if (entry.key == null)
- {
- throw new MalformedKeyringException(
- "could not decode X.509 key");
- }
+ throw new MalformedKeyringException("could not decode X.509 key");
}
}
else
- {
- throw new MalformedKeyringException("unsupported public key type: "
- + type);
- }
+ throw new MalformedKeyringException("unsupported public key type: " + type);
return entry;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns the public key.
- *
+ *
* @return The public key.
*/
public PublicKey getKey()
@@ -182,8 +157,6 @@ public final class PublicKeyEntry extends PrimitiveEntry
payload = key.getEncoded();
}
else
- {
- throw new IllegalArgumentException("cannot encode public key");
- }
+ throw new IllegalArgumentException("cannot encode public key");
}
}