Skip to content

Commit 42818cf

Browse files
committed
fixed checkstyle issues.
1 parent ec3dbd0 commit 42818cf

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

pg/src/main/java/org/bouncycastle/bcpg/FingerprintUtil.java

+21-16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class FingerprintUtil
66
/**
77
* Derive a 64 bit key-id from a version 6 OpenPGP fingerprint.
88
* For v6 keys, the key-id corresponds to the left-most 8 octets of the fingerprint.
9+
*
910
* @param v6Fingerprint 32 byte fingerprint
1011
* @return key-id
1112
*/
@@ -17,6 +18,7 @@ public static long keyIdFromV6Fingerprint(byte[] v6Fingerprint)
1718
/**
1819
* Derive a 64 bit key-id from a version 5 LibrePGP fingerprint.
1920
* For such keys, the key-id corresponds to the left-most 8 octets of the fingerprint.
21+
*
2022
* @param v5Fingerprint 32 byte fingerprint
2123
* @return key-id
2224
*/
@@ -28,6 +30,7 @@ public static long keyIdFromLibrePgpFingerprint(byte[] v5Fingerprint)
2830
/**
2931
* Derive a 64 bit key-id from a version 4 OpenPGP fingerprint.
3032
* For v4 keys, the key-id corresponds to the right-most 8 octets of the fingerprint.
33+
*
3134
* @param v4Fingerprint 20 byte fingerprint
3235
* @return key-id
3336
*/
@@ -38,6 +41,7 @@ public static long keyIdFromV4Fingerprint(byte[] v4Fingerprint)
3841

3942
/**
4043
* Convert the left-most 8 bytes from the given array to a long.
44+
*
4145
* @param bytes bytes
4246
* @return long
4347
*/
@@ -47,18 +51,19 @@ public static long longFromLeftMostBytes(byte[] bytes)
4751
{
4852
throw new IllegalArgumentException("Byte array MUST contain at least 8 bytes");
4953
}
50-
return ((bytes[0] & 0xffL) << 56) |
51-
((bytes[1] & 0xffL) << 48) |
52-
((bytes[2] & 0xffL) << 40) |
53-
((bytes[3] & 0xffL) << 32) |
54-
((bytes[4] & 0xffL) << 24) |
55-
((bytes[5] & 0xffL) << 16) |
56-
((bytes[6] & 0xffL) << 8) |
57-
((bytes[7] & 0xffL));
54+
return ((bytes[0] & 0xffL) << 56) |
55+
((bytes[1] & 0xffL) << 48) |
56+
((bytes[2] & 0xffL) << 40) |
57+
((bytes[3] & 0xffL) << 32) |
58+
((bytes[4] & 0xffL) << 24) |
59+
((bytes[5] & 0xffL) << 16) |
60+
((bytes[6] & 0xffL) << 8) |
61+
((bytes[7] & 0xffL));
5862
}
5963

6064
/**
6165
* Convert the right-most 8 bytes from the given array to a long.
66+
*
6267
* @param bytes bytes
6368
* @return long
6469
*/
@@ -69,13 +74,13 @@ public static long longFromRightMostBytes(byte[] bytes)
6974
throw new IllegalArgumentException("Byte array MUST contain at least 8 bytes");
7075
}
7176
int i = bytes.length;
72-
return ((bytes[i - 8] & 0xffL) << 56) |
73-
((bytes[i - 7] & 0xffL) << 48) |
74-
((bytes[i - 6] & 0xffL) << 40) |
75-
((bytes[i - 5] & 0xffL) << 32) |
76-
((bytes[i - 4] & 0xffL) << 24) |
77-
((bytes[i - 3] & 0xffL) << 16) |
78-
((bytes[i - 2] & 0xffL) << 8) |
79-
((bytes[i - 1] & 0xffL));
77+
return ((bytes[i - 8] & 0xffL) << 56) |
78+
((bytes[i - 7] & 0xffL) << 48) |
79+
((bytes[i - 6] & 0xffL) << 40) |
80+
((bytes[i - 5] & 0xffL) << 32) |
81+
((bytes[i - 4] & 0xffL) << 24) |
82+
((bytes[i - 3] & 0xffL) << 16) |
83+
((bytes[i - 2] & 0xffL) << 8) |
84+
((bytes[i - 1] & 0xffL));
8085
}
8186
}

pg/src/test/java/org/bouncycastle/bcpg/test/FingerprintUtilTest.java

+26-14
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,66 @@
44
import org.bouncycastle.util.encoders.Hex;
55
import org.bouncycastle.util.test.SimpleTest;
66

7-
public class FingerprintUtilTest extends SimpleTest {
8-
9-
private void testKeyIdFromTooShortFails() {
7+
public class FingerprintUtilTest
8+
extends SimpleTest
9+
{
10+
private void testKeyIdFromTooShortFails()
11+
{
1012
byte[] decoded = new byte[1];
11-
try {
13+
try
14+
{
1215
FingerprintUtil.keyIdFromV4Fingerprint(decoded);
1316
fail("Expected exception");
14-
} catch (IllegalArgumentException e) {
17+
}
18+
catch (IllegalArgumentException e)
19+
{
1520
// expected
1621
}
1722
}
1823

19-
private void testV4KeyIdFromFingerprint() {
24+
private void testV4KeyIdFromFingerprint()
25+
{
2026
String fingerprint = "1D018C772DF8C5EF86A1DCC9B4B509CB5936E03E";
2127
byte[] decoded = Hex.decode(fingerprint);
2228
isEquals("v4 key-id from fingerprint mismatch",
23-
-5425419407118114754L, FingerprintUtil.keyIdFromV4Fingerprint(decoded));
29+
-5425419407118114754L, FingerprintUtil.keyIdFromV4Fingerprint(decoded));
2430
}
2531

26-
private void testV6KeyIdFromFingerprint() {
32+
private void testV6KeyIdFromFingerprint()
33+
{
2734
String fingerprint = "cb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc9";
2835
byte[] decoded = Hex.decode(fingerprint);
2936
isEquals("v6 key-id from fingerprint mismatch",
30-
-3812177997909612905L, FingerprintUtil.keyIdFromV6Fingerprint(decoded));
37+
-3812177997909612905L, FingerprintUtil.keyIdFromV6Fingerprint(decoded));
3138
}
3239

33-
private void testLibrePgpKeyIdFromFingerprint() {
40+
private void testLibrePgpKeyIdFromFingerprint()
41+
{
3442
// v6 key-ids are derived from fingerprints the same way as LibrePGP does
3543
String fingerprint = "cb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc9";
3644
byte[] decoded = Hex.decode(fingerprint);
3745
isEquals("LibrePGP key-id from fingerprint mismatch",
38-
-3812177997909612905L, FingerprintUtil.keyIdFromLibrePgpFingerprint(decoded));
46+
-3812177997909612905L, FingerprintUtil.keyIdFromLibrePgpFingerprint(decoded));
3947
}
4048

4149
@Override
42-
public String getName() {
50+
public String getName()
51+
{
4352
return "FingerprintUtilTest";
4453
}
4554

4655
@Override
47-
public void performTest() throws Exception {
56+
public void performTest()
57+
throws Exception
58+
{
4859
testV4KeyIdFromFingerprint();
4960
testV6KeyIdFromFingerprint();
5061
testKeyIdFromTooShortFails();
5162
testLibrePgpKeyIdFromFingerprint();
5263
}
5364

54-
public static void main(String[] args) {
65+
public static void main(String[] args)
66+
{
5567
runTest(new FingerprintUtilTest());
5668
}
5769
}

0 commit comments

Comments
 (0)