Skip to content

Commit 992b1da

Browse files
committed
Refactor to use Pack
1 parent 95e8063 commit 992b1da

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

pg/src/main/java/org/bouncycastle/openpgp/PGPPublicKey.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.bouncycastle.bcpg.UserIDPacket;
3030
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
3131
import org.bouncycastle.util.Arrays;
32+
import org.bouncycastle.util.Pack;
3233

3334
/**
3435
* general class to handle a PGP public key object.
@@ -67,25 +68,11 @@ private void init(KeyFingerPrintCalculator fingerPrintCalculator)
6768
}
6869
else if (publicPk.getVersion() == PublicKeyPacket.VERSION_4)
6970
{
70-
this.keyID = ((long)(fingerprint[fingerprint.length - 8] & 0xff) << 56)
71-
| ((long)(fingerprint[fingerprint.length - 7] & 0xff) << 48)
72-
| ((long)(fingerprint[fingerprint.length - 6] & 0xff) << 40)
73-
| ((long)(fingerprint[fingerprint.length - 5] & 0xff) << 32)
74-
| ((long)(fingerprint[fingerprint.length - 4] & 0xff) << 24)
75-
| ((long)(fingerprint[fingerprint.length - 3] & 0xff) << 16)
76-
| ((long)(fingerprint[fingerprint.length - 2] & 0xff) << 8)
77-
| ((fingerprint[fingerprint.length - 1] & 0xff));
71+
this.keyID = Pack.bigEndianToLong(fingerprint, fingerprint.length - 8);
7872
}
7973
else if (publicPk.getVersion() == PublicKeyPacket.VERSION_6)
8074
{
81-
this.keyID = ((long)(fingerprint[0] & 0xff) << 56)
82-
| ((long)(fingerprint[1] & 0xff) << 48)
83-
| ((long)(fingerprint[2] & 0xff) << 40)
84-
| ((long)(fingerprint[3] & 0xff) << 32)
85-
| ((long)(fingerprint[4] & 0xff) << 24)
86-
| ((long)(fingerprint[5] & 0xff) << 16)
87-
| ((long)(fingerprint[6] & 0xff) << 8)
88-
| ((long)(fingerprint[7] & 0xff));
75+
this.keyID = Pack.bigEndianToLong(fingerprint, 0);
8976
}
9077

9178
// key strength

0 commit comments

Comments
 (0)