Skip to content

Commit 5d349f6

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

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@ public KeyIdentifier(byte[] fingerprint, long keyId)
7878
*/
7979
public KeyIdentifier(long keyId)
8080
{
81-
this(null, keyId);
81+
if (keyId == 0L)
82+
{
83+
this.keyId = 0L;
84+
this.fingerprint = new byte[0];
85+
}
86+
else
87+
{
88+
this.keyId = keyId;
89+
this.fingerprint = null;
90+
}
8291
}
8392

8493
/**
8594
* Create a wildcard {@link KeyIdentifier}.
8695
*/
8796
private KeyIdentifier()
8897
{
89-
this(new byte[0], 0L);
98+
this(0L);
9099
}
91100

92101
/**
@@ -132,7 +141,7 @@ public long getKeyId()
132141
*/
133142
public boolean isWildcard()
134143
{
135-
return keyId == 0L && fingerprint.length == 0;
144+
return keyId == 0L && (fingerprint == null || fingerprint.length == 0);
136145
}
137146

138147
/**

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

Lines changed: 3 additions & 0 deletions
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)