Skip to content

Minor java code cleanup #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -110,7 +110,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.0.1</version>
<configuration>
<minmemory>128m</minmemory>
<maxmemory>1024m</maxmemory>
Expand Down Expand Up @@ -172,7 +172,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<version>2.22.0</version>
<configuration>
<includes>
<include>**/AllTestsSuite.java</include>
Expand All @@ -193,7 +193,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<version>2.22.0</version>
<configuration>
<includes>
<include>**/FastTestsOnlySuite.java</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public DefaultCryptoMaterialsManager(MasterKeyProvider<?> mkp) {
}

pubKey = deserializeTrailingKeyFromEc(request.getAlgorithm(), serializedPubKey);
} catch (final GeneralSecurityException ex) {
} catch (final IllegalStateException ex) {
throw new AwsCryptoException(ex);
}
}
Expand All @@ -136,10 +136,7 @@ public DefaultCryptoMaterialsManager(MasterKeyProvider<?> mkp) {
.build();
}

private PublicKey deserializeTrailingKeyFromEc(
CryptoAlgorithm algo,
String pubKey
) throws GeneralSecurityException {
private PublicKey deserializeTrailingKeyFromEc(CryptoAlgorithm algo, String pubKey) {
return TrailingSignatureAlgorithm.forCryptoAlgorithm(algo).deserializePublicKey(pubKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.amazonaws.encryptionsdk.CryptoMaterialsManager;
import com.amazonaws.encryptionsdk.DefaultCryptoMaterialsManager;
import com.amazonaws.encryptionsdk.MasterKeyProvider;
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
import com.amazonaws.encryptionsdk.internal.EncryptionContextSerializer;
import com.amazonaws.encryptionsdk.internal.Utils;
import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequest;
Expand Down Expand Up @@ -249,7 +250,7 @@ private CachingCryptoMaterialsManager(Builder builder) {
partitionId.getBytes(StandardCharsets.UTF_8)
);
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
throw new AwsCryptoException(e);
}
}

Expand Down Expand Up @@ -349,7 +350,7 @@ private byte[] getCacheIdentifier(EncryptionMaterialsRequest req) {

return digest.digest();
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
throw new AwsCryptoException(e);
}
}

Expand Down Expand Up @@ -377,7 +378,7 @@ private byte[] getCacheIdentifier(DecryptionMaterialsRequest req) {

return digest.digest();
} catch (GeneralSecurityException e) {
throw new RuntimeException(e);
throw new AwsCryptoException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
package com.amazonaws.encryptionsdk.internal;

import java.io.ByteArrayOutputStream;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;

Expand All @@ -33,7 +31,6 @@
* {@link BlockDecryptionHandler}.
*/
class BlockEncryptionHandler implements CryptoHandler {
private static final SecureRandom RND = new SecureRandom();
private final SecretKey encryptionKey_;
private final CryptoAlgorithm cryptoAlgo_;
private final int nonceLen_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class Constants {
* Default length of the message identifier used to uniquely identify every
* ciphertext created by this library.
*/
public final static int MESSAGE_ID_LEN = 16;
public static final int MESSAGE_ID_LEN = 16;

private Constants() {
// Prevent instantiation
Expand All @@ -27,39 +27,39 @@ private Constants() {
/**
* Marker for identifying the final frame.
*/
public final static int ENDFRAME_SEQUENCE_NUMBER = ~0; // is 0xFFFFFFFF
public static final int ENDFRAME_SEQUENCE_NUMBER = ~0; // is 0xFFFFFFFF

/**
* The identifier for non-final frames in the framing content type. This value is used as part
* of the additional authenticated data (AAD) when encryption of content in a frame.
*/
public final static String FRAME_STRING_ID = "AWSKMSEncryptionClient Frame";
public static final String FRAME_STRING_ID = "AWSKMSEncryptionClient Frame";

/**
* The identifier for the final frame in the framing content type. This value is used as part of
* the additional authenticated data (AAD) when encryption of content in a frame.
*/
public final static String FINAL_FRAME_STRING_ID = "AWSKMSEncryptionClient Final Frame";
public static final String FINAL_FRAME_STRING_ID = "AWSKMSEncryptionClient Final Frame";

/**
* The identifier for the single block content type. This value is used as part of the
* additional authenticated data (AAD) when encryption of content in a single block.
*/
public final static String SINGLE_BLOCK_STRING_ID = "AWSKMSEncryptionClient Single Block";
public static final String SINGLE_BLOCK_STRING_ID = "AWSKMSEncryptionClient Single Block";

/**
* Maximum length of the content that can be encrypted in GCM mode.
*/
public final static long GCM_MAX_CONTENT_LEN = (1L << 36) - 32;
public static final long GCM_MAX_CONTENT_LEN = (1L << 36) - 32;

public final static int MAX_NONCE_LENGTH = (1 << 8) - 1;
public static final int MAX_NONCE_LENGTH = (1 << 8) - 1;

/**
* Maximum value of an unsigned short.
*/
public final static int UNSIGNED_SHORT_MAX_VAL = (1 << 16) - 1;
public static final int UNSIGNED_SHORT_MAX_VAL = (1 << 16) - 1;

public final static long MAX_FRAME_NUMBER = (1L << 32) - 1;
public static final long MAX_FRAME_NUMBER = (1L << 32) - 1;

public static final String EC_PUBLIC_KEY_FIELD = "aws-crypto-public-key";
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ private void readHeaderFields(final CiphertextHeaders ciphertextHeaders) {

private void updateTrailingSignature(final CiphertextHeaders headers) {
if (trailingSig_ != null) {
final byte[] reserializedHeaders = ciphertextHeaders_.toByteArray();
final byte[] reserializedHeaders = headers.toByteArray();
updateTrailingSignature(reserializedHeaders, 0, reserializedHeaders.length);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.SecureRandom;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Comparator;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;

/**
* Internal utility methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public class VersionInfo {
/**
* The current version number of the ciphertext produced by this library.
*/
public final static byte CURRENT_CIPHERTEXT_VERSION = 1;
public static final byte CURRENT_CIPHERTEXT_VERSION = 1;

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public byte[] toByteArray() {
dataStream.close();
return outBytes.toByteArray();
} catch (IOException e) {
throw new RuntimeException("Failed to serialize cipher frame headers", e);
throw new AwsCryptoException("Failed to serialize cipher frame headers", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum CiphertextType {
* This is a static method so the map is created when the class is loaded.
* This enables fast lookups of the CiphertextType given a value.
*/
private static final Map<Byte, CiphertextType> ID_MAPPING = new HashMap<Byte, CiphertextType>();
private static final Map<Byte, CiphertextType> ID_MAPPING = new HashMap<>();
static {
for (final CiphertextType s : EnumSet.allOf(CiphertextType.class)) {
ID_MAPPING.put(s.value_, s);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/com/amazonaws/encryptionsdk/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import static org.junit.Assert.assertTrue;

import java.util.Arrays;
import java.util.Collections;

import org.junit.Test;

import com.amazonaws.encryptionsdk.internal.Utils;

public class UtilsTest {
@Test
public void compareObjectIdentityTest() throws Exception {
public void compareObjectIdentityTest() {
assertNotEquals(0, Utils.compareObjectIdentity(null, new Object()));
assertNotEquals(0, Utils.compareObjectIdentity(new Object(), null));

Expand Down Expand Up @@ -63,7 +62,7 @@ public void compareObjectIdentity_handlesHashCodeCollisions() {
}

@Test
public void testSaturatingAdd() throws Exception {
public void testSaturatingAdd() {
assertEquals(0, Utils.saturatingAdd(0, 0));
assertEquals(2, Utils.saturatingAdd(1, 1));
assertEquals(-2, Utils.saturatingAdd(-1, -1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class CacheIdentifierTests {
contextFull.put("encryption", "context");
}

CachingCryptoMaterialsManager cmm;

static List<KeyBlob> keyBlobs = Arrays.asList(
new KeyBlob("this is a provider ID", "this is some key info".getBytes(UTF_8),
"super secret key, now with encryption!".getBytes(UTF_8)
Expand Down
Loading