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/06/06 23:32:57 UTC
[commons-crypto] 01/07: No need to nest else.
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
commit 99cbed5a8f9192a32dab07d49e01daf082bed69a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Jun 6 18:18:53 2020 -0400
No need to nest else.
---
.../crypto/cipher/OpenSslGaloisCounterMode.java | 16 +++--
.../commons/crypto/jna/OpenSslNativeJna.java | 70 ++++++++--------------
2 files changed, 31 insertions(+), 55 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
index 29682c8..efbae23 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/OpenSslGaloisCounterMode.java
@@ -95,13 +95,12 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
input.get(inputBuf, 0, inputLen);
inBuffer.write(inputBuf, 0, inputLen);
return 0;
- } else {
- len = OpenSslNative.update(context, input, input.position(),
- input.remaining(), output, output.position(),
- output.remaining());
- input.position(input.limit());
- output.position(output.position() + len);
}
+ len = OpenSslNative.update(context, input, input.position(),
+ input.remaining(), output, output.position(),
+ output.remaining());
+ input.position(input.limit());
+ output.position(output.position() + len);
return len;
}
@@ -119,10 +118,9 @@ class OpenSslGaloisCounterMode extends OpenSslFeedbackCipher {
// is successfully verified
inBuffer.write(input, inputOffset, inputLen);
return 0;
- } else {
- return OpenSslNative.updateByteArray(context, input, inputOffset,
- inputLen, output, outputOffset, output.length - outputOffset);
}
+ return OpenSslNative.updateByteArray(context, input, inputOffset,
+ inputLen, output, outputOffset, output.length - outputOffset);
}
@Override
diff --git a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
index 4680580..d5bc738 100644
--- a/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
+++ b/src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java
@@ -73,9 +73,8 @@ class OpenSslNativeJna {
public static PointerByReference ENGINE_by_id(final String string) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.ENGINE_by_id(string);
- } else {
- return OpenSsl10XNativeJna.ENGINE_by_id(string);
}
+ return OpenSsl10XNativeJna.ENGINE_by_id(string);
}
public static void ENGINE_finish(final PointerByReference rdrandEngine) {
@@ -97,81 +96,71 @@ class OpenSslNativeJna {
public static int ENGINE_init(final PointerByReference rdrandEngine) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.ENGINE_init(rdrandEngine);
- } else {
- return OpenSsl10XNativeJna.ENGINE_init(rdrandEngine);
}
+ return OpenSsl10XNativeJna.ENGINE_init(rdrandEngine);
}
public static int ENGINE_set_default(final PointerByReference rdrandEngine, final int eNGINE_METHOD_RAND) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.ENGINE_set_default(rdrandEngine, eNGINE_METHOD_RAND);
- } else {
- return OpenSsl10XNativeJna.ENGINE_set_default(rdrandEngine, eNGINE_METHOD_RAND);
}
+ return OpenSsl10XNativeJna.ENGINE_set_default(rdrandEngine, eNGINE_METHOD_RAND);
}
public static String ERR_error_string(final NativeLong err, final Object object) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.ERR_error_string(err, null);
- } else {
- return OpenSsl10XNativeJna.ERR_error_string(err, null);
}
+ return OpenSsl10XNativeJna.ERR_error_string(err, null);
}
public static NativeLong ERR_peek_error() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.ERR_peek_error();
- } else {
- return OpenSsl10XNativeJna.ERR_peek_error();
}
+ return OpenSsl10XNativeJna.ERR_peek_error();
}
public static PointerByReference EVP_aes_128_cbc() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_128_cbc();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_128_cbc();
}
+ return OpenSsl10XNativeJna.EVP_aes_128_cbc();
}
public static PointerByReference EVP_aes_128_ctr() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_128_ctr();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_128_ctr();
}
+ return OpenSsl10XNativeJna.EVP_aes_128_ctr();
}
public static PointerByReference EVP_aes_192_cbc() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_192_cbc();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_192_cbc();
}
+ return OpenSsl10XNativeJna.EVP_aes_192_cbc();
}
public static PointerByReference EVP_aes_192_ctr() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_192_ctr();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_192_ctr();
}
+ return OpenSsl10XNativeJna.EVP_aes_192_ctr();
}
public static PointerByReference EVP_aes_256_cbc() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_256_cbc();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_256_cbc();
}
+ return OpenSsl10XNativeJna.EVP_aes_256_cbc();
}
public static PointerByReference EVP_aes_256_ctr() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_aes_256_ctr();
- } else {
- return OpenSsl10XNativeJna.EVP_aes_256_ctr();
}
+ return OpenSsl10XNativeJna.EVP_aes_256_ctr();
}
public static void EVP_CIPHER_CTX_free(final PointerByReference context) {
@@ -185,9 +174,8 @@ class OpenSslNativeJna {
public static PointerByReference EVP_CIPHER_CTX_new() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_CIPHER_CTX_new();
- } else {
- return OpenSsl10XNativeJna.EVP_CIPHER_CTX_new();
}
+ return OpenSsl10XNativeJna.EVP_CIPHER_CTX_new();
}
public static void EVP_CIPHER_CTX_set_padding(final PointerByReference context, final int padding) {
@@ -202,9 +190,8 @@ class OpenSslNativeJna {
final int[] outlen) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_CipherFinal_ex(context, outBuffer, outlen);
- } else {
- return OpenSsl10XNativeJna.EVP_CipherFinal_ex(context, outBuffer, outlen);
}
+ return OpenSsl10XNativeJna.EVP_CipherFinal_ex(context, outBuffer, outlen);
}
public static int EVP_CipherInit_ex(final PointerByReference context, final PointerByReference algo,
@@ -212,10 +199,9 @@ class OpenSslNativeJna {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_CipherInit_ex(context, algo, null, encoded, iv,
cipherMode);
- } else {
- return OpenSsl10XNativeJna.EVP_CipherInit_ex(context, algo, null, encoded, iv,
- cipherMode);
}
+ return OpenSsl10XNativeJna.EVP_CipherInit_ex(context, algo, null, encoded, iv,
+ cipherMode);
}
public static int EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuffer,
@@ -223,65 +209,57 @@ class OpenSslNativeJna {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.EVP_CipherUpdate(context, outBuffer, outlen, inBuffer,
remaining);
- } else {
- return OpenSsl10XNativeJna.EVP_CipherUpdate(context, outBuffer, outlen, inBuffer,
- remaining);
}
+ return OpenSsl10XNativeJna.EVP_CipherUpdate(context, outBuffer, outlen, inBuffer,
+ remaining);
}
public static int RAND_bytes(final ByteBuffer buf, final int length) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.RAND_bytes(buf, length);
- } else {
- return OpenSsl10XNativeJna.RAND_bytes(buf, length);
}
+ return OpenSsl10XNativeJna.RAND_bytes(buf, length);
}
public static PointerByReference RAND_get_rand_method() {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.RAND_get_rand_method();
- } else {
- return OpenSsl10XNativeJna.RAND_get_rand_method();
}
+ return OpenSsl10XNativeJna.RAND_get_rand_method();
}
public static PointerByReference RAND_SSLeay() {
if (VERSION == VERSION_1_1_X) {
return null;
- } else {
- return OpenSsl10XNativeJna.RAND_SSLeay();
}
+ return OpenSsl10XNativeJna.RAND_SSLeay();
}
public static String OpenSSLVersion(final int i) {
if (VERSION == VERSION_1_1_X) {
return OpenSsl11XNativeJna.OpenSSL_version(i);
- } else {
- return OpenSsl10XNativeJna.SSLeay_version(i);
}
+ return OpenSsl10XNativeJna.SSLeay_version(i);
}
public static void ENGINE_load_rdrand() {
if (VERSION == VERSION_1_1_X) {
return;
- } else {
- OpenSsl10XNativeJna.ENGINE_load_rdrand();
}
+ OpenSsl10XNativeJna.ENGINE_load_rdrand();
}
public static void ENGINE_cleanup() {
if (VERSION == VERSION_1_1_X) {
return;
- } else {
- OpenSsl10XNativeJna.ENGINE_cleanup();
}
+ OpenSsl10XNativeJna.ENGINE_cleanup();
}
public static void EVP_CIPHER_CTX_cleanup(final PointerByReference context) {
if (VERSION == VERSION_1_1_X) {
return;
- } else {
- OpenSsl10XNativeJna.EVP_CIPHER_CTX_cleanup(context);
}
+ OpenSsl10XNativeJna.EVP_CIPHER_CTX_cleanup(context);
}
}
\ No newline at end of file