Skip to content

Commit

Permalink
JNI/JCE: fix unused imports and variable warnings reported by Cursor/…
Browse files Browse the repository at this point in the history
…VSCode
  • Loading branch information
cconlon committed Feb 24, 2025
1 parent 2eeb8f1 commit 3484ade
Show file tree
Hide file tree
Showing 54 changed files with 84 additions and 356 deletions.
27 changes: 3 additions & 24 deletions src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

import com.wolfssl.wolfcrypt.WolfCrypt;
import com.wolfssl.wolfcrypt.Asn;
import com.wolfssl.wolfcrypt.Aes;
import com.wolfssl.wolfcrypt.AesGcm;
import com.wolfssl.wolfcrypt.Des3;
import com.wolfssl.wolfcrypt.Rsa;
import com.wolfssl.wolfcrypt.Rng;

import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE Cipher (AES, 3DES) wrapper
*/
Expand Down Expand Up @@ -144,6 +140,9 @@ private WolfCryptCipher(CipherType type, CipherMode mode,
case WC_DES3:
blockSize = Des3.BLOCK_SIZE;
break;

case WC_RSA:
break;
}

if (WolfCryptDebug.DEBUG) {
Expand Down Expand Up @@ -450,8 +449,6 @@ private void wolfCryptSetIV(AlgorithmParameterSpec spec,
private void wolfCryptSetKey(Key key)
throws InvalidKeyException {

int ret = 0;
long[] idx = {0};
byte[] encodedKey;

/* validate key class type */
Expand Down Expand Up @@ -611,27 +608,10 @@ private boolean isBlockCipher() {
return isBlockCipher;
}

/* return 1 if cipher is a block cipher and lenth is a block
* length multiple, otherwise 0 */
private int isValidBlockLength(int length) {

/* skip if not a block cipher */
if (isBlockCipher() == false) {
return 1;
}

if ((length % this.blockSize) != 0) {
return 0;
}

return 1;
}

private byte[] wolfCryptUpdate(byte[] input, int inputOffset, int len)
throws IllegalArgumentException {

int blocks = 0;
int remaining = 0;
int bytesToProcess = 0;
byte[] output = null;
byte[] tmpIn = null;
Expand Down Expand Up @@ -666,7 +646,6 @@ private byte[] wolfCryptUpdate(byte[] input, int inputOffset, int len)

/* calculate blocks and partial non-block size remaining */
blocks = buffered.length / blockSize;
remaining = buffered.length % blockSize;
bytesToProcess = blocks * blockSize;

/* if PKCS#5/7 padding, and decrypting, hold on to last block for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import javax.crypto.SecretKey;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.DESedeKeySpec;
Expand All @@ -48,8 +47,6 @@
import com.wolfssl.wolfcrypt.Dh;
import com.wolfssl.wolfcrypt.Ecc;

import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE Key Agreement wrapper
*/
Expand Down Expand Up @@ -236,9 +233,7 @@ protected byte[] engineGenerateSecret()
protected int engineGenerateSecret(byte[] sharedSecret, int offset)
throws IllegalStateException, ShortBufferException {

int ret = 0;
byte tmp[] = null;
long sz[] = null;

if (this.state != EngineState.WC_PUBKEY_DONE)
throw new IllegalStateException(
Expand Down Expand Up @@ -355,7 +350,6 @@ protected SecretKey engineGenerateSecret(String algorithm)
private void wcInitDHParams(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException {

int ret = 0;
byte paramP[] = null;
byte paramG[] = null;
byte dhPriv[] = null;
Expand Down Expand Up @@ -433,8 +427,6 @@ private void wcInitDHParams(Key key, AlgorithmParameterSpec params)
private void getCurveFromSpec(AlgorithmParameterSpec spec)
throws InvalidAlgorithmParameterException {

int fieldSz = 0;

if (spec instanceof ECGenParameterSpec) {

ECGenParameterSpec gs = (ECGenParameterSpec)spec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@
import java.security.InvalidAlgorithmParameterException;

import java.security.SecureRandom;
import java.security.AlgorithmParameters;
import java.security.spec.AlgorithmParameterSpec;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.spec.KeySpec;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.security.spec.ECGenParameterSpec;
import java.security.spec.RSAKeyGenParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.interfaces.ECPrivateKey;
Expand All @@ -56,8 +51,6 @@
import com.wolfssl.wolfcrypt.Dh;
import com.wolfssl.wolfcrypt.Rng;

import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE KeyPairGenerator wrapper class
*/
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@
import java.security.NoSuchAlgorithmException;
import javax.crypto.SecretKey;

import com.wolfssl.wolfcrypt.WolfCrypt;
import com.wolfssl.wolfcrypt.Md5;
import com.wolfssl.wolfcrypt.Sha;
import com.wolfssl.wolfcrypt.Sha256;
import com.wolfssl.wolfcrypt.Sha384;
import com.wolfssl.wolfcrypt.Sha512;
import com.wolfssl.wolfcrypt.Hmac;

import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE Mac wrapper
*/
Expand All @@ -53,7 +50,6 @@ enum HmacType {
}

private Hmac hmac = null;
private HmacType hmacType = null;
private int nativeHmacType = 0;
private int digestSize = 0;

Expand All @@ -63,7 +59,6 @@ enum HmacType {
private WolfCryptMac(HmacType type)
throws NoSuchAlgorithmException {

this.hmacType = type;
hmac = new Hmac();

switch (type) {
Expand Down Expand Up @@ -125,7 +120,6 @@ protected int engineGetMacLength() {
protected void engineInit(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException {

int ret = 0;
byte[] encodedKey;

/* key must be of type SecretKey */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

package com.wolfssl.provider.jce;

import java.util.Arrays;
import java.security.MessageDigestSpi;
import javax.crypto.ShortBufferException;

import com.wolfssl.wolfcrypt.Md5;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE MD5 MessageDigest wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

package com.wolfssl.provider.jce;

import java.util.Arrays;
import java.security.MessageDigestSpi;
import javax.crypto.ShortBufferException;

import com.wolfssl.wolfcrypt.Sha;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE SHA-1 MessageDigest wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

package com.wolfssl.provider.jce;

import java.util.Arrays;
import java.security.MessageDigestSpi;
import javax.crypto.ShortBufferException;

import com.wolfssl.wolfcrypt.Sha256;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE SHA2-256 MessageDigest wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

package com.wolfssl.provider.jce;

import java.util.Arrays;
import java.security.MessageDigestSpi;
import javax.crypto.ShortBufferException;

import com.wolfssl.wolfcrypt.Sha384;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE SHA2-384 MessageDigest wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

package com.wolfssl.provider.jce;

import java.util.Arrays;
import java.security.MessageDigestSpi;
import javax.crypto.ShortBufferException;

import com.wolfssl.wolfcrypt.Sha512;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE SHA2-512 MessageDigest wrapper
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/wolfssl/provider/jce/WolfCryptPBEKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@

import java.util.Arrays;
import java.security.spec.InvalidKeySpecException;
import javax.security.auth.Destroyable;
import javax.crypto.interfaces.PBEKey;

/**
* wolfCrypt PBEKey implementation.
*/
public class WolfCryptPBEKey implements PBEKey, Destroyable {
public class WolfCryptPBEKey implements PBEKey {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@
import java.security.cert.CRL;
import java.security.cert.X509CRL;
import java.security.cert.X509CRLSelector;
import java.security.InvalidAlgorithmParameterException;
import javax.security.auth.x500.X500Principal;

import com.wolfssl.wolfcrypt.Fips;
import com.wolfssl.wolfcrypt.WolfCrypt;
import com.wolfssl.wolfcrypt.WolfSSLCertManager;
import com.wolfssl.wolfcrypt.WolfCryptException;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfJCE implementation of CertPathValidator for PKIX (X.509)
Expand Down Expand Up @@ -265,7 +263,6 @@ private void callCertPathCheckers(X509Certificate cert,

int i = 0;
List<PKIXCertPathChecker> pathCheckers = null;
PKIXCertPathChecker checker = null;

if (cert == null || params == null) {
throw new CertPathValidatorException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.security.SecureRandomSpi;

import com.wolfssl.wolfcrypt.Rng;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE RNG/SecureRandom wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import com.wolfssl.wolfcrypt.WolfCrypt;
import com.wolfssl.wolfcrypt.Pwdbased;
import com.wolfssl.provider.jce.WolfCryptDebug;

/**
* wolfCrypt JCE SecretKeyFactory implementation.
Expand Down Expand Up @@ -435,12 +434,6 @@ private KeySpec getKeySpecFromPBEKeyByType(PBEKey key, Class<?> keySpec)
protected synchronized KeySpec engineGetKeySpec(SecretKey key,
Class<?> keySpec) throws InvalidKeySpecException {

PBEKey pKey = null;
int iterations = 0;
char[] password = null;
byte[] salt = null;
byte[] encoded = null;

log("returning KeySpec from SecretKey in requested type");

if (key == null) {
Expand Down
Loading

0 comments on commit 3484ade

Please sign in to comment.