You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/08/23 19:20:27 UTC
[commons-crypto] branch master updated: - Simplify exception
handling. - Add missing Javadoc.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
The following commit(s) were added to refs/heads/master by this push:
new 0fb231f - Simplify exception handling. - Add missing Javadoc.
0fb231f is described below
commit 0fb231f10ea77e2c84175bb0cfb33795ae227140
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Aug 23 15:20:20 2020 -0400
- Simplify exception handling.
- Add missing Javadoc.
---
.../org/apache/commons/crypto/cipher/OpenSslNative.java | 2 +-
.../apache/commons/crypto/stream/CryptoInputStream.java | 7 ++-----
.../apache/commons/crypto/stream/CryptoOutputStream.java | 15 +++------------
.../commons/crypto/stream/CtrCryptoInputStream.java | 16 +++-------------
.../commons/crypto/stream/CtrCryptoOutputStream.java | 16 +++-------------
.../crypto/stream/PositionedCryptoInputStream.java | 16 ++--------------
6 files changed, 14 insertions(+), 58 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
index dcaf37a..7b3ce66 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslNative.java
@@ -146,7 +146,7 @@ class OpenSslNative {
*
* @param context The cipher context address
* @param type CtrlValues
- * @param arg
+ * @param arg argument like a tag length
* @param data byte buffer or null
* @return return 0 if there is any error, else return 1.
*/
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
index fc0225b..95a000f 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -22,8 +22,7 @@ import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
+import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Objects;
@@ -469,9 +468,7 @@ public class CryptoInputStream extends InputStream implements
protected void initCipher() throws IOException {
try {
cipher.init(Cipher.DECRYPT_MODE, key, params);
- } catch (final InvalidKeyException e) {
- throw new IOException(e);
- } catch (final InvalidAlgorithmParameterException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
}
diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
index ff62e6e..adebc72 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoOutputStream.java
@@ -22,16 +22,13 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
+import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Objects;
import java.util.Properties;
-import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
@@ -338,9 +335,7 @@ public class CryptoOutputStream extends OutputStream implements
protected void initCipher() throws IOException {
try {
cipher.init(Cipher.ENCRYPT_MODE, key, params);
- } catch (final InvalidKeyException e) {
- throw new IOException(e);
- } catch (final InvalidAlgorithmParameterException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
}
@@ -382,11 +377,7 @@ public class CryptoOutputStream extends OutputStream implements
try {
cipher.doFinal(inBuffer, outBuffer);
- } catch (final ShortBufferException e) {
- throw new IOException(e);
- } catch (final IllegalBlockSizeException e) {
- throw new IOException(e);
- } catch (final BadPaddingException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
index db7d914..6e684e6 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoInputStream.java
@@ -21,14 +21,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
+import java.security.GeneralSecurityException;
import java.util.Properties;
-import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@@ -572,9 +568,7 @@ public class CtrCryptoInputStream extends CryptoInputStream {
CtrCryptoInputStream.calculateIV(initIV, counter, iv);
try {
cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
- } catch (final InvalidKeyException e) {
- throw new IOException(e);
- } catch (final InvalidAlgorithmParameterException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
cipherReset = false;
@@ -616,11 +610,7 @@ public class CtrCryptoInputStream extends CryptoInputStream {
cipher.doFinal(inBuffer, out);
cipherReset = true;
}
- } catch (final ShortBufferException e) {
- throw new IOException(e);
- } catch (final IllegalBlockSizeException e) {
- throw new IOException(e);
- } catch (final BadPaddingException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
}
diff --git a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
index 7f8fc98..7f73b5a 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CtrCryptoOutputStream.java
@@ -21,14 +21,10 @@ import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.WritableByteChannel;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
+import java.security.GeneralSecurityException;
import java.util.Properties;
-import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
@@ -337,9 +333,7 @@ public class CtrCryptoOutputStream extends CryptoOutputStream {
CtrCryptoInputStream.calculateIV(initIV, counter, iv);
try {
cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv));
- } catch (final InvalidKeyException e) {
- throw new IOException(e);
- } catch (final InvalidAlgorithmParameterException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
cipherReset = false;
@@ -364,11 +358,7 @@ public class CtrCryptoOutputStream extends CryptoOutputStream {
cipher.doFinal(inBuffer, out);
cipherReset = true;
}
- } catch (final ShortBufferException e) {
- throw new IOException(e);
- } catch (final BadPaddingException e) {
- throw new IOException(e);
- } catch (final IllegalBlockSizeException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
}
diff --git a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
index 284cad2..cb1441c 100644
--- a/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/PositionedCryptoInputStream.java
@@ -20,16 +20,11 @@ package org.apache.commons.crypto.stream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.InvalidKeyException;
import java.util.Properties;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
-import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.ShortBufferException;
import javax.crypto.spec.IvParameterSpec;
import org.apache.commons.crypto.cipher.CryptoCipher;
@@ -250,11 +245,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
state.getCryptoCipher().doFinal(inByteBuffer, outByteBuffer);
state.reset(true);
}
- } catch (final ShortBufferException e) {
- throw new IOException(e);
- } catch (final IllegalBlockSizeException e) {
- throw new IOException(e);
- } catch (final BadPaddingException e) {
+ } catch (final GeneralSecurityException e) {
throw new IOException(e);
}
}
@@ -302,10 +293,7 @@ public class PositionedCryptoInputStream extends CtrCryptoInputStream {
try {
state.getCryptoCipher().init(Cipher.DECRYPT_MODE, key,
new IvParameterSpec(iv));
- } catch (final InvalidKeyException e) {
- throw new IOException(e);
- } catch (final InvalidAlgorithmParameterException e) {
- throw new IOException(e);
+ } catch (final GeneralSecurityException e) {
}
state.reset(false);
}