From d0580918fa4eb7c61212c4f42840c21aa3e74850 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 30 Oct 2020 12:38:59 +0100 Subject: [PATCH] Fix checkstyle issues --- .../key/generation/GenerateWithEmptyPassphrase.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java index 5c7d60b2..d31f27cf 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateWithEmptyPassphrase.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Paul Schaub. + * Copyright 2020 Wiktor Kwapisiewicz, 2020 Paul Schaub. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,9 @@ package org.pgpainless.key.generation; import static org.junit.Assert.assertNotNull; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.NoSuchAlgorithmException; -import java.util.Iterator; import org.bouncycastle.openpgp.PGPException; import org.junit.Test; @@ -30,10 +28,17 @@ import org.pgpainless.key.generation.type.RSA; import org.pgpainless.key.generation.type.length.RsaLength; import org.pgpainless.util.Passphrase; +/** + * Reproduce behavior of https://github.com/pgpainless/pgpainless/issues/16 + * and verify that the fix is working. + * + * The issue is that the implementation of {@link Passphrase#emptyPassphrase()} would set the underlying + * char array to null, which caused an NPE later on. + */ public class GenerateWithEmptyPassphrase { @Test - public void test() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { + public void testGeneratingKeyWithEmptyPassphraseDoesNotThrow() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { assertNotNull(PGPainless.generateKeyRing() .withMasterKey(KeySpec.getBuilder(RSA.withLength(RsaLength._3072)) .withDefaultKeyFlags()