17
17
import static org .junit .Assert .assertEquals ;
18
18
19
19
import java .nio .charset .StandardCharsets ;
20
+ import java .util .Arrays ;
20
21
import java .util .HashMap ;
21
22
import java .util .Map ;
22
23
@@ -173,13 +174,9 @@ public void checkKeyLen() {
173
174
}
174
175
175
176
private KeyBlob generateRandomKeyBlob (int idLen , int infoLen , int keyLen ) {
176
- final byte [] idBytes = RandomBytesGenerator .generate (idLen );
177
- // negative bytes translate into U+FFFD, so no thanks
178
- for (int i = 0 ; i < idBytes .length ; i ++) {
179
- if (idBytes [i ] < 0 ) {
180
- idBytes [i ] = (byte ) (idBytes [i ] - Byte .MIN_VALUE );
181
- }
182
- }
177
+ final byte [] idBytes = new byte [idLen ];
178
+ Arrays .fill (idBytes , (byte ) 'A' );
179
+
183
180
final byte [] infoBytes = RandomBytesGenerator .generate (infoLen );
184
181
final byte [] keyBytes = RandomBytesGenerator .generate (keyLen );
185
182
@@ -196,7 +193,7 @@ private void assertKeyBlobsEqual(KeyBlob b1, KeyBlob b2) {
196
193
@ Test
197
194
public void checkKeyProviderIdLenUnsigned () {
198
195
// provider id length is too large for a signed short but fits in unsigned
199
- final KeyBlob blob = generateRandomKeyBlob (Short . MAX_VALUE + 1 , Short .MAX_VALUE , Short .MAX_VALUE );
196
+ final KeyBlob blob = generateRandomKeyBlob (Constants . UNSIGNED_SHORT_MAX_VAL , Short .MAX_VALUE , Short .MAX_VALUE );
200
197
final byte [] arr = blob .toByteArray ();
201
198
202
199
assertKeyBlobsEqual (deserialize (arr ), blob );
@@ -205,7 +202,7 @@ public void checkKeyProviderIdLenUnsigned() {
205
202
@ Test
206
203
public void checkKeyProviderInfoLenUnsigned () {
207
204
// provider info length is too large for a signed short but fits in unsigned
208
- final KeyBlob blob = generateRandomKeyBlob (Short .MAX_VALUE , Short . MAX_VALUE + 2 , Short .MAX_VALUE );
205
+ final KeyBlob blob = generateRandomKeyBlob (Short .MAX_VALUE , Constants . UNSIGNED_SHORT_MAX_VAL , Short .MAX_VALUE );
209
206
final byte [] arr = blob .toByteArray ();
210
207
211
208
assertKeyBlobsEqual (deserialize (arr ), blob );
@@ -214,7 +211,7 @@ public void checkKeyProviderInfoLenUnsigned() {
214
211
@ Test
215
212
public void checkKeyLenUnsigned () {
216
213
// key length is too large for a signed short but fits in unsigned
217
- final KeyBlob blob = generateRandomKeyBlob (Short .MAX_VALUE , Short .MAX_VALUE , Short . MAX_VALUE + 3 );
214
+ final KeyBlob blob = generateRandomKeyBlob (Short .MAX_VALUE , Short .MAX_VALUE , Constants . UNSIGNED_SHORT_MAX_VAL );
218
215
final byte [] arr = blob .toByteArray ();
219
216
220
217
assertKeyBlobsEqual (deserialize (arr ), blob );
0 commit comments