Skip to content

Commit 2ff8410

Browse files
author
gefeili
committed
Refactor on OnePassSignaturePacket and add tests back to OperatorBcTest
1 parent 205878e commit 2ff8410

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.bouncycastle.bcpg;
22

33
import org.bouncycastle.util.Arrays;
4+
import org.bouncycastle.util.Pack;
45
import org.bouncycastle.util.io.Streams;
56

67
import java.io.ByteArrayOutputStream;
@@ -74,15 +75,7 @@ else if (version == VERSION_6)
7475
fingerprint = new byte[32];
7576
in.readFully(fingerprint);
7677

77-
// TODO: Replace with FingerprintUtil
78-
keyID = ((fingerprint[0] & 0xffL) << 56) |
79-
((fingerprint[1] & 0xffL) << 48) |
80-
((fingerprint[2] & 0xffL) << 40) |
81-
((fingerprint[3] & 0xffL) << 32) |
82-
((fingerprint[4] & 0xffL) << 24) |
83-
((fingerprint[5] & 0xffL) << 16) |
84-
((fingerprint[6] & 0xffL) << 8) |
85-
((fingerprint[7] & 0xffL));
78+
keyID = Pack.bigEndianToLong(fingerprint, 0);
8679
}
8780
else
8881
{
@@ -154,15 +147,7 @@ public OnePassSignaturePacket(
154147
this.salt = salt;
155148
this.fingerprint = fingerprint;
156149
this.isContaining = (isNested) ? 0 : 1;
157-
// TODO: Replace with FingerprintUtil
158-
keyID = ((fingerprint[0] & 0xffL) << 56) |
159-
((fingerprint[1] & 0xffL) << 48) |
160-
((fingerprint[2] & 0xffL) << 40) |
161-
((fingerprint[3] & 0xffL) << 32) |
162-
((fingerprint[4] & 0xffL) << 24) |
163-
((fingerprint[5] & 0xffL) << 16) |
164-
((fingerprint[6] & 0xffL) << 8) |
165-
((fingerprint[7] & 0xffL));
150+
this.keyID = Pack.bigEndianToLong(fingerprint, 0);
166151
}
167152

168153
/**

pg/src/test/java/org/bouncycastle/openpgp/test/OperatorBcTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
import org.bouncycastle.openpgp.PGPSignature;
5151
import org.bouncycastle.openpgp.bc.BcPGPObjectFactory;
5252
import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory;
53+
import org.bouncycastle.openpgp.operator.PBESecretKeyDecryptor;
5354
import org.bouncycastle.openpgp.operator.PGPContentVerifier;
5455
import org.bouncycastle.openpgp.operator.PGPDigestCalculator;
5556
import org.bouncycastle.openpgp.operator.PGPDigestCalculatorProvider;
5657
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
58+
import org.bouncycastle.openpgp.operator.bc.BcPBESecretKeyDecryptorBuilder;
5759
import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
5860
import org.bouncycastle.openpgp.operator.bc.BcPGPDataEncryptorBuilder;
5961
import org.bouncycastle.openpgp.operator.bc.BcPGPDigestCalculatorProvider;
@@ -101,9 +103,9 @@ public void performTest()
101103
testX25519HKDF();
102104
testKeyRings();
103105
testBcPGPKeyPair();
104-
// testBcPGPDataEncryptorBuilder();
106+
testBcPGPDataEncryptorBuilder();
105107
testBcPGPContentVerifierBuilderProvider();
106-
//testBcPBESecretKeyDecryptorBuilder();
108+
testBcPBESecretKeyDecryptorBuilder();
107109
testBcKeyFingerprintCalculator();
108110
testBcStandardDigests();
109111
}
@@ -179,12 +181,12 @@ public void operation()
179181
});
180182
}
181183

182-
// public void testBcPBESecretKeyDecryptorBuilder()
183-
// throws PGPException
184-
// {
185-
// final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(BcPGPDSAElGamalTest.pass);
186-
// decryptor.recoverKeyData(SymmetricKeyAlgorithmTags.CAMELLIA_256, new byte[32], new byte[12], new byte[16], 0, 16);
187-
// }
184+
public void testBcPBESecretKeyDecryptorBuilder()
185+
throws PGPException
186+
{
187+
final PBESecretKeyDecryptor decryptor = new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(BcPGPDSAElGamalTest.pass);
188+
decryptor.recoverKeyData(SymmetricKeyAlgorithmTags.CAMELLIA_256, new byte[32], new byte[12], new byte[16], 0, 16);
189+
}
188190

189191
public void testBcPGPContentVerifierBuilderProvider()
190192
throws Exception

0 commit comments

Comments
 (0)