Skip to content

Commit

Permalink
Ignore zero-length key ID
Browse files Browse the repository at this point in the history
See gh-3
  • Loading branch information
wilkinsona committed Nov 19, 2024
1 parent 3701fa3 commit 115a2a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private PGPSecretKey getSigningKey(PGPSecretKeyRingCollection keyrings, String k
for (PGPSecretKeyRing keyring : keyrings) {
Iterable<PGPSecretKey> secretKeys = keyring::getSecretKeys;
for (PGPSecretKey candidate : secretKeys) {
if (keyId != null) {
if (keyId != null && keyId.length() > 0) {
String candidateKeyId = String.format("%08X", 0xFFFFFFFFL & candidate.getKeyID());
if (keyId.equals(candidateKeyId)) {
return candidate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ void getWhenSigningKeyIsKeyAndIdMatchesReturnsSigner() throws Exception {
assertThat(signer.sign(this.sourceContent)).isEqualTo(this.expectedSignature);
}

@Test
void getWhenSigningKeyIsKeyAndIdIsEmptyReturnsSigner() throws Exception {
ArmoredAsciiSigner signer = ArmoredAsciiSigner.get(FIXED, this.signingKeyContent, this.passphrase, "");
assertThat(signer.sign(this.sourceContent)).isEqualTo(this.expectedSignature);
}

@Test
void getWhenSigningKeyIsSubkeyAndIdMatchesReturnsSigner() throws Exception {
ArmoredAsciiSigner signer = ArmoredAsciiSigner.get(FIXED, this.signingSubkeyContent, this.passphrase,
Expand Down

0 comments on commit 115a2a1

Please sign in to comment.