Skip to content

Commit 272fc41

Browse files
committed
Fix NPE when calling isWildcard() on a KeyIdentifer created from 0L keyId
1 parent a8d871c commit 272fc41

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.List;
55
import java.util.Locale;
66

7+
import org.bouncycastle.internal.asn1.gnu.GNUObjectIdentifiers;
78
import org.bouncycastle.util.Arrays;
89
import org.bouncycastle.util.encoders.Hex;
910

@@ -78,15 +79,24 @@ public KeyIdentifier(byte[] fingerprint, long keyId)
7879
*/
7980
public KeyIdentifier(long keyId)
8081
{
81-
this(null, keyId);
82+
if (keyId == 0L)
83+
{
84+
this.keyId = 0L;
85+
this.fingerprint = new byte[0];
86+
}
87+
else
88+
{
89+
this.keyId = keyId;
90+
this.fingerprint = null;
91+
}
8292
}
8393

8494
/**
8595
* Create a wildcard {@link KeyIdentifier}.
8696
*/
8797
private KeyIdentifier()
8898
{
89-
this(new byte[0], 0L);
99+
this(0L);
90100
}
91101

92102
/**

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

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ private void testWildcardIdentifier()
5959
wildcard.isWildcard());
6060

6161
isEquals("*", wildcard.toString());
62+
63+
KeyIdentifier id = new KeyIdentifier(0L);
64+
isTrue(id.isWildcard());
6265
}
6366

6467
private void testIdentifierFromKeyId()

0 commit comments

Comments
 (0)