Skip to content

Commit 782cc3b

Browse files
committed
OpenPGPKeyGenerator: Allow for empty UserIDs, prevent newlines/CRs
1 parent 196569e commit 782cc3b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pg/src/main/java/org/bouncycastle/openpgp/api/OpenPGPKeyGenerator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,13 @@ public WithPrimaryKey addUserId(
380380
throws PGPException
381381
{
382382
// care - needs to run with Java 5.
383-
if (userId == null || userId.trim().length() == 0)
383+
if (userId == null)
384384
{
385-
throw new IllegalArgumentException("User-ID cannot be null or empty.");
385+
throw new IllegalArgumentException("User-ID cannot be null.");
386+
}
387+
if (userId.contains("\n") || userId.contains("\r"))
388+
{
389+
throw new IllegalArgumentException("User-ID cannot contain newlines and/or carriage returns.");
386390
}
387391

388392
SignatureParameters parameters = Utils.applySignatureParameters(signatureParameters,

0 commit comments

Comments
 (0)