Skip to content

Commit

Permalink
Move fingerprint util class out to #1636
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Apr 24, 2024
1 parent 310062a commit c7926d2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 133 deletions.
73 changes: 0 additions & 73 deletions pg/src/main/java/org/bouncycastle/bcpg/FingerprintUtil.java

This file was deleted.

20 changes: 18 additions & 2 deletions pg/src/main/java/org/bouncycastle/bcpg/OnePassSignaturePacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ else if (version == VERSION_6)
fingerprint = new byte[32];
in.readFully(fingerprint);

keyID = FingerprintUtil.keyIdFromV6Fingerprint(fingerprint);
// TODO: Replace with FingerprintUtil
keyID = ((fingerprint[0] & 0xffL) << 56) |
((fingerprint[1] & 0xffL) << 48) |
((fingerprint[2] & 0xffL) << 40) |
((fingerprint[3] & 0xffL) << 32) |
((fingerprint[4] & 0xffL) << 24) |
((fingerprint[5] & 0xffL) << 16) |
((fingerprint[6] & 0xffL) << 8) |
((fingerprint[7] & 0xffL));
}
else
{
Expand Down Expand Up @@ -145,7 +153,15 @@ public OnePassSignaturePacket(
this.salt = salt;
this.fingerprint = fingerprint;
this.isContaining = (isNested) ? 0 : 1;
this.keyID = FingerprintUtil.keyIdFromV6Fingerprint(fingerprint);
// TODO: Replace with FingerprintUtil
keyID = ((fingerprint[0] & 0xffL) << 56) |
((fingerprint[1] & 0xffL) << 48) |
((fingerprint[2] & 0xffL) << 40) |
((fingerprint[3] & 0xffL) << 32) |
((fingerprint[4] & 0xffL) << 24) |
((fingerprint[5] & 0xffL) << 16) |
((fingerprint[6] & 0xffL) << 8) |
((fingerprint[7] & 0xffL));
}

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ private void roundtripV3Packet() throws IOException {
private void roundtripV6Packet() throws IOException {
byte[] salt = new byte[HashUtils.getV6SignatureSaltSizeInBytes(HashAlgorithmTags.SHA512)];
byte[] fingerprint = Hex.decode("CB186C4F0609A697E4D52DFA6C722B0C1F1E27C18A56708F6525EC27BAD9ACC9");
long keyID = ((fingerprint[0] & 0xffL) << 56) |
((fingerprint[1] & 0xffL) << 48) |
((fingerprint[2] & 0xffL) << 40) |
((fingerprint[3] & 0xffL) << 32) |
((fingerprint[4] & 0xffL) << 24) |
((fingerprint[5] & 0xffL) << 16) |
((fingerprint[6] & 0xffL) << 8) |
((fingerprint[7] & 0xffL));

new SecureRandom().nextBytes(salt);
OnePassSignaturePacket before = new OnePassSignaturePacket(
Expand All @@ -131,7 +139,7 @@ private void roundtripV6Packet() throws IOException {
isEncodingEqual("Fingerprint mismatch",
fingerprint, before.getFingerprint());
isEquals("Derived key-ID mismatch",
FingerprintUtil.keyIdFromV6Fingerprint(fingerprint), before.getKeyID());
keyID, before.getKeyID());
isTrue("non-nested OPS is expected to be containing",
before.isContaining());

Expand Down

0 comments on commit c7926d2

Please sign in to comment.