File tree 2 files changed +9
-3
lines changed
main/java/com/google/crypto/tink/internal
test/java/com/google/crypto/tink/internal
2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,8 @@ public static int randKeyId() {
35
35
int result = 0 ;
36
36
while (result == 0 ) {
37
37
secureRandom .nextBytes (rand );
38
- // TODO(b/148124847): Other languages create key_ids with the MSB set, so we should here too.
39
38
result =
40
- ((rand [0 ] & 0x7f ) << 24 )
39
+ ((rand [0 ] & 0xff ) << 24 )
41
40
| ((rand [1 ] & 0xff ) << 16 )
42
41
| ((rand [2 ] & 0xff ) << 8 )
43
42
| (rand [3 ] & 0xff );
Original file line number Diff line number Diff line change 16
16
package com .google .crypto .tink .internal ;
17
17
18
18
import static com .google .common .truth .Truth .assertThat ;
19
+ import static java .nio .charset .StandardCharsets .US_ASCII ;
19
20
import static org .junit .Assert .assertFalse ;
20
21
import static org .junit .Assert .assertThrows ;
21
22
import static org .junit .Assert .assertTrue ;
@@ -38,11 +39,17 @@ public void randKeyId_repeatedCallsShouldOutputDifferentValues() {
38
39
.isAtLeast (2 );
39
40
}
40
41
42
+ @ Test
43
+ public void randKeyId_repeatedCallsShouldOutputANegativeValue () {
44
+ assertThat (IntStream .range (0 , 100 ).map (unused -> Util .randKeyId ()).min ().getAsInt ())
45
+ .isAtMost (0 );
46
+ }
47
+
41
48
@ Test
42
49
public void toBytesFromPrintableAscii_works () throws Exception {
43
50
String pureAsciiString =
44
51
"!\" #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\ ]^_`abcdefghijklmnopqrstuvwxyz{|}~" ;
45
- Bytes pureAsciiBytes = Bytes .copyFrom (pureAsciiString .getBytes ("ASCII" ));
52
+ Bytes pureAsciiBytes = Bytes .copyFrom (pureAsciiString .getBytes (US_ASCII ));
46
53
assertThat (Util .toBytesFromPrintableAscii (pureAsciiString )).isEqualTo (pureAsciiBytes );
47
54
}
48
55
You can’t perform that action at this time.
0 commit comments