Skip to content

Commit eb8702e

Browse files
Ajay Kemparajbdonlan
Ajay Kemparaj
authored andcommitted
Minor java code cleanup
1 parent 7cca10f commit eb8702e

15 files changed

+44
-54
lines changed

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
<plugin>
101101
<groupId>org.apache.maven.plugins</groupId>
102102
<artifactId>maven-compiler-plugin</artifactId>
103-
<version>3.1</version>
103+
<version>3.8.0</version>
104104
<configuration>
105105
<source>1.8</source>
106106
<target>1.8</target>
@@ -110,7 +110,7 @@
110110
<plugin>
111111
<groupId>org.apache.maven.plugins</groupId>
112112
<artifactId>maven-javadoc-plugin</artifactId>
113-
<version>2.9.1</version>
113+
<version>3.0.1</version>
114114
<configuration>
115115
<minmemory>128m</minmemory>
116116
<maxmemory>1024m</maxmemory>
@@ -172,7 +172,7 @@
172172
<plugin>
173173
<groupId>org.apache.maven.plugins</groupId>
174174
<artifactId>maven-surefire-plugin</artifactId>
175-
<version>2.20</version>
175+
<version>2.22.0</version>
176176
<configuration>
177177
<includes>
178178
<include>**/AllTestsSuite.java</include>
@@ -193,7 +193,7 @@
193193
<plugin>
194194
<groupId>org.apache.maven.plugins</groupId>
195195
<artifactId>maven-surefire-plugin</artifactId>
196-
<version>2.20</version>
196+
<version>2.22.0</version>
197197
<configuration>
198198
<includes>
199199
<include>**/FastTestsOnlySuite.java</include>

src/main/java/com/amazonaws/encryptionsdk/DefaultCryptoMaterialsManager.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public DefaultCryptoMaterialsManager(MasterKeyProvider<?> mkp) {
125125
}
126126

127127
pubKey = deserializeTrailingKeyFromEc(request.getAlgorithm(), serializedPubKey);
128-
} catch (final GeneralSecurityException ex) {
128+
} catch (final IllegalStateException ex) {
129129
throw new AwsCryptoException(ex);
130130
}
131131
}
@@ -136,10 +136,7 @@ public DefaultCryptoMaterialsManager(MasterKeyProvider<?> mkp) {
136136
.build();
137137
}
138138

139-
private PublicKey deserializeTrailingKeyFromEc(
140-
CryptoAlgorithm algo,
141-
String pubKey
142-
) throws GeneralSecurityException {
139+
private PublicKey deserializeTrailingKeyFromEc(CryptoAlgorithm algo, String pubKey) {
143140
return TrailingSignatureAlgorithm.forCryptoAlgorithm(algo).deserializePublicKey(pubKey);
144141
}
145142

src/main/java/com/amazonaws/encryptionsdk/caching/CachingCryptoMaterialsManager.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.amazonaws.encryptionsdk.CryptoMaterialsManager;
1212
import com.amazonaws.encryptionsdk.DefaultCryptoMaterialsManager;
1313
import com.amazonaws.encryptionsdk.MasterKeyProvider;
14+
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
1415
import com.amazonaws.encryptionsdk.internal.EncryptionContextSerializer;
1516
import com.amazonaws.encryptionsdk.internal.Utils;
1617
import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequest;
@@ -249,7 +250,7 @@ private CachingCryptoMaterialsManager(Builder builder) {
249250
partitionId.getBytes(StandardCharsets.UTF_8)
250251
);
251252
} catch (GeneralSecurityException e) {
252-
throw new RuntimeException(e);
253+
throw new AwsCryptoException(e);
253254
}
254255
}
255256

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

350351
return digest.digest();
351352
} catch (GeneralSecurityException e) {
352-
throw new RuntimeException(e);
353+
throw new AwsCryptoException(e);
353354
}
354355
}
355356

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

378379
return digest.digest();
379380
} catch (GeneralSecurityException e) {
380-
throw new RuntimeException(e);
381+
throw new AwsCryptoException(e);
381382
}
382383
}
383384

src/main/java/com/amazonaws/encryptionsdk/internal/BlockEncryptionHandler.java

-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
package com.amazonaws.encryptionsdk.internal;
1515

1616
import java.io.ByteArrayOutputStream;
17-
import java.security.SecureRandom;
18-
1917
import javax.crypto.Cipher;
2018
import javax.crypto.SecretKey;
2119

@@ -33,7 +31,6 @@
3331
* {@link BlockDecryptionHandler}.
3432
*/
3533
class BlockEncryptionHandler implements CryptoHandler {
36-
private static final SecureRandom RND = new SecureRandom();
3734
private final SecretKey encryptionKey_;
3835
private final CryptoAlgorithm cryptoAlgo_;
3936
private final int nonceLen_;

src/main/java/com/amazonaws/encryptionsdk/internal/Constants.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class Constants {
1818
* Default length of the message identifier used to uniquely identify every
1919
* ciphertext created by this library.
2020
*/
21-
public final static int MESSAGE_ID_LEN = 16;
21+
public static final int MESSAGE_ID_LEN = 16;
2222

2323
private Constants() {
2424
// Prevent instantiation
@@ -27,39 +27,39 @@ private Constants() {
2727
/**
2828
* Marker for identifying the final frame.
2929
*/
30-
public final static int ENDFRAME_SEQUENCE_NUMBER = ~0; // is 0xFFFFFFFF
30+
public static final int ENDFRAME_SEQUENCE_NUMBER = ~0; // is 0xFFFFFFFF
3131

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

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

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

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

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

5757
/**
5858
* Maximum value of an unsigned short.
5959
*/
60-
public final static int UNSIGNED_SHORT_MAX_VAL = (1 << 16) - 1;
60+
public static final int UNSIGNED_SHORT_MAX_VAL = (1 << 16) - 1;
6161

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

6464
public static final String EC_PUBLIC_KEY_FIELD = "aws-crypto-public-key";
6565
}

src/main/java/com/amazonaws/encryptionsdk/internal/DecryptionHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ private void readHeaderFields(final CiphertextHeaders ciphertextHeaders) {
515515

516516
private void updateTrailingSignature(final CiphertextHeaders headers) {
517517
if (trailingSig_ != null) {
518-
final byte[] reserializedHeaders = ciphertextHeaders_.toByteArray();
518+
final byte[] reserializedHeaders = headers.toByteArray();
519519
updateTrailingSignature(reserializedHeaders, 0, reserializedHeaders.length);
520520
}
521521
}

src/main/java/com/amazonaws/encryptionsdk/internal/FrameEncryptionHandler.java

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.nio.ByteBuffer;
1717
import java.nio.ByteOrder;
18-
import java.security.SecureRandom;
1918

2019
import javax.crypto.Cipher;
2120
import javax.crypto.SecretKey;

src/main/java/com/amazonaws/encryptionsdk/internal/Utils.java

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Comparator;
2222
import java.util.WeakHashMap;
2323
import java.util.concurrent.atomic.AtomicLong;
24-
import java.util.regex.Pattern;
2524

2625
/**
2726
* Internal utility methods.

src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public class VersionInfo {
3333
/**
3434
* The current version number of the ciphertext produced by this library.
3535
*/
36-
public final static byte CURRENT_CIPHERTEXT_VERSION = 1;
36+
public static final byte CURRENT_CIPHERTEXT_VERSION = 1;
3737

3838
}

src/main/java/com/amazonaws/encryptionsdk/model/CipherFrameHeaders.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public byte[] toByteArray() {
113113
dataStream.close();
114114
return outBytes.toByteArray();
115115
} catch (IOException e) {
116-
throw new RuntimeException("Failed to serialize cipher frame headers", e);
116+
throw new AwsCryptoException("Failed to serialize cipher frame headers", e);
117117
}
118118
}
119119

src/main/java/com/amazonaws/encryptionsdk/model/CiphertextType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum CiphertextType {
3333
* This is a static method so the map is created when the class is loaded.
3434
* This enables fast lookups of the CiphertextType given a value.
3535
*/
36-
private static final Map<Byte, CiphertextType> ID_MAPPING = new HashMap<Byte, CiphertextType>();
36+
private static final Map<Byte, CiphertextType> ID_MAPPING = new HashMap<>();
3737
static {
3838
for (final CiphertextType s : EnumSet.allOf(CiphertextType.class)) {
3939
ID_MAPPING.put(s.value_, s);

src/test/java/com/amazonaws/encryptionsdk/UtilsTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
import static org.junit.Assert.assertTrue;
66

77
import java.util.Arrays;
8-
import java.util.Collections;
98

109
import org.junit.Test;
1110

1211
import com.amazonaws.encryptionsdk.internal.Utils;
1312

1413
public class UtilsTest {
1514
@Test
16-
public void compareObjectIdentityTest() throws Exception {
15+
public void compareObjectIdentityTest() {
1716
assertNotEquals(0, Utils.compareObjectIdentity(null, new Object()));
1817
assertNotEquals(0, Utils.compareObjectIdentity(new Object(), null));
1918

@@ -63,7 +62,7 @@ public void compareObjectIdentity_handlesHashCodeCollisions() {
6362
}
6463

6564
@Test
66-
public void testSaturatingAdd() throws Exception {
65+
public void testSaturatingAdd() {
6766
assertEquals(0, Utils.saturatingAdd(0, 0));
6867
assertEquals(2, Utils.saturatingAdd(1, 1));
6968
assertEquals(-2, Utils.saturatingAdd(-1, -1));

src/test/java/com/amazonaws/encryptionsdk/caching/CacheIdentifierTests.java

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public class CacheIdentifierTests {
3737
contextFull.put("encryption", "context");
3838
}
3939

40-
CachingCryptoMaterialsManager cmm;
41-
4240
static List<KeyBlob> keyBlobs = Arrays.asList(
4341
new KeyBlob("this is a provider ID", "this is some key info".getBytes(UTF_8),
4442
"super secret key, now with encryption!".getBytes(UTF_8)

0 commit comments

Comments
 (0)