@@ -6,6 +6,7 @@ public class FingerprintUtil
6
6
/**
7
7
* Derive a 64 bit key-id from a version 6 OpenPGP fingerprint.
8
8
* For v6 keys, the key-id corresponds to the left-most 8 octets of the fingerprint.
9
+ *
9
10
* @param v6Fingerprint 32 byte fingerprint
10
11
* @return key-id
11
12
*/
@@ -17,6 +18,7 @@ public static long keyIdFromV6Fingerprint(byte[] v6Fingerprint)
17
18
/**
18
19
* Derive a 64 bit key-id from a version 5 LibrePGP fingerprint.
19
20
* For such keys, the key-id corresponds to the left-most 8 octets of the fingerprint.
21
+ *
20
22
* @param v5Fingerprint 32 byte fingerprint
21
23
* @return key-id
22
24
*/
@@ -28,6 +30,7 @@ public static long keyIdFromLibrePgpFingerprint(byte[] v5Fingerprint)
28
30
/**
29
31
* Derive a 64 bit key-id from a version 4 OpenPGP fingerprint.
30
32
* For v4 keys, the key-id corresponds to the right-most 8 octets of the fingerprint.
33
+ *
31
34
* @param v4Fingerprint 20 byte fingerprint
32
35
* @return key-id
33
36
*/
@@ -38,6 +41,7 @@ public static long keyIdFromV4Fingerprint(byte[] v4Fingerprint)
38
41
39
42
/**
40
43
* Convert the left-most 8 bytes from the given array to a long.
44
+ *
41
45
* @param bytes bytes
42
46
* @return long
43
47
*/
@@ -47,18 +51,19 @@ public static long longFromLeftMostBytes(byte[] bytes)
47
51
{
48
52
throw new IllegalArgumentException ("Byte array MUST contain at least 8 bytes" );
49
53
}
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 ));
58
62
}
59
63
60
64
/**
61
65
* Convert the right-most 8 bytes from the given array to a long.
66
+ *
62
67
* @param bytes bytes
63
68
* @return long
64
69
*/
@@ -69,13 +74,13 @@ public static long longFromRightMostBytes(byte[] bytes)
69
74
throw new IllegalArgumentException ("Byte array MUST contain at least 8 bytes" );
70
75
}
71
76
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 ));
80
85
}
81
86
}
0 commit comments