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 2022/12/13 03:09:16 UTC
[commons-crypto] branch master updated: No need to override local var, use a ternary instead
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 24d1130 No need to override local var, use a ternary instead
24d1130 is described below
commit 24d1130b23792867e6cfb01a7da920b7115907b4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Dec 12 22:09:12 2022 -0500
No need to override local var, use a ternary instead
---
src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java | 5 +----
src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java | 8 ++------
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
index 6cf0c15..3b0b829 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslCipher.java
@@ -106,10 +106,7 @@ final class OpenSslCipher implements CryptoCipher {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(params, "params");
- int cipherMode = OpenSsl.DECRYPT_MODE;
- if (mode == Cipher.ENCRYPT_MODE) {
- cipherMode = OpenSsl.ENCRYPT_MODE;
- }
+ final int cipherMode = mode == Cipher.ENCRYPT_MODE ? OpenSsl.ENCRYPT_MODE: OpenSsl.DECRYPT_MODE;
openSslEngine.init(cipherMode, key.getEncoded(), params);
initialized = true;
}
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
index a01b7e0..e88afc4 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslJnaCipher.java
@@ -91,17 +91,13 @@ final class OpenSslJnaCipher implements CryptoCipher {
throws InvalidKeyException, InvalidAlgorithmParameterException {
Objects.requireNonNull(key, "key");
Objects.requireNonNull(params, "params");
- int cipherMode = OpenSslNativeJna.OOSL_JNA_DECRYPT_MODE;
- if (mode == Cipher.ENCRYPT_MODE) {
- cipherMode = OpenSslNativeJna.OOSL_JNA_ENCRYPT_MODE;
- }
- final byte[] iv;
+ final int cipherMode = mode == Cipher.ENCRYPT_MODE ? OpenSslNativeJna.OOSL_JNA_ENCRYPT_MODE : OpenSslNativeJna.OOSL_JNA_DECRYPT_MODE;
if (!(params instanceof IvParameterSpec)) {
// other AlgorithmParameterSpec such as GCMParameterSpec is not
// supported now.
throw new InvalidAlgorithmParameterException("Illegal parameters");
}
- iv = ((IvParameterSpec) params).getIV();
+ final byte[] iv = ((IvParameterSpec) params).getIV();
if ((algorithmMode == AlgorithmMode.AES_CBC || algorithmMode == AlgorithmMode.AES_CTR) && iv.length != IV_LENGTH) {
throw new InvalidAlgorithmParameterException("Wrong IV length: must be 16 bytes long");