summaryrefslogtreecommitdiff
path: root/gnu/javax/crypto/keyring/EncryptedEntry.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/javax/crypto/keyring/EncryptedEntry.java')
-rw-r--r--gnu/javax/crypto/keyring/EncryptedEntry.java66
1 files changed, 14 insertions, 52 deletions
diff --git a/gnu/javax/crypto/keyring/EncryptedEntry.java b/gnu/javax/crypto/keyring/EncryptedEntry.java
index a47a3c6fa..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,17 +170,13 @@ 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);
- modeAttr.put(IMode.STATE, new Integer(state));
+ modeAttr.put(IMode.STATE, Integer.valueOf(state));
modeAttr.put(IMode.IV, iv);
try
{