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VsUCh47V8VcfG
+ymCxxq80r+4GfFtt/HC+l9fPUnDLuXpAWEM2GPUzcauUoEXxZK6nhstYCRlKlQcK
+Tn+LtCC7SGpYlqvwWBzAnOYP9+eZfSJ897g0AiTEhK0JsBlDAb3UAWHYHkAkVa1+
+oU/UedhPC4j2Q7RzPQFMun6aGkaDrntCxvT7IFiMplPG7iy0JDd6ubrWSzivABEB
+AAGJATYEGAEKACAWIQQILQAv4wNQfEJ6I/NEWemKCmiQ+wUCXsQvzAIbDAAKCRBE
+WemKCmiQ+xoBB/9BAmlHQUmVl/bkwszAcyXkR5HsyA4htMJt+6GKlqftuhLP0SGK
+Il+7GeK6NqNdQXxXG5Wj6dn7ZqWalQRA0evEa6VLH+74zrn0llWfzTPIcP1bHW7l
+uYaOzZ1z/q4FoEGNJxp/jdToZ4970OXLzqY/G/QlMJIlXWCC0EXNYbKCEpOE9uvW
+h4kWe5xeGOmhZylYbzurTDzqEtKy+LZ9f2xNYn6ElcWtwxsxwSY7L9B3eNcCYE46
+Np6uqzPffB9s7PHW46yEL1lQs6ME+9hBGyjeVop+Wg9qkh3YCrp+KY5Vkmdndwkn
+Th4FnTpcCiS06fCVHHC5kelh+H6TgRA+XQ/V
+=WGUq
+-----END PGP PUBLIC KEY BLOCK-----
final boolean encrypted;
- TestData(String name, boolean encrypted) {
+ final boolean keyValue;
+
+ TestData(String name, boolean encrypted, boolean keyValue) {
this.name = name;
this.encrypted = encrypted;
+ this.keyValue = keyValue;
}
@Override
@Parameters(name = "{0}")
public static TestData[] initTestData() {
return new TestData[] {
- new TestData("2FB05DBB70FC07CB84C13431F640CA6CEA1DBF8A", false),
- new TestData("66CCECEC2AB46A9735B10FEC54EDF9FD0F77BAF9", true),
- new TestData("F727FAB884DA3BD402B6E0F5472E108D21033124", true),
- new TestData("faked", false) };
+ new TestData("AFDA8EA10E185ACF8C0D0F8885A0EF61A72ECB11", false, false),
+ new TestData("2FB05DBB70FC07CB84C13431F640CA6CEA1DBF8A", false, true),
+ new TestData("66CCECEC2AB46A9735B10FEC54EDF9FD0F77BAF9", true, true),
+ new TestData("F727FAB884DA3BD402B6E0F5472E108D21033124", true, true),
+ new TestData("faked", false, true) };
}
private static byte[] readTestKey(String filename) throws Exception {
@Test
public void testKeyRead() throws Exception {
- byte[] bytes = readTestKey(data.name + ".key");
- assertEquals('(', bytes[0]);
- assertEquals(')', bytes[bytes.length - 1]);
+ if (data.keyValue) {
+ byte[] bytes = readTestKey(data.name + ".key");
+ assertEquals('(', bytes[0]);
+ assertEquals(')', bytes[bytes.length - 1]);
+ }
try (InputStream pubIn = this.getClass()
.getResourceAsStream(data.name + ".asc")) {
if (pubIn != null) {
try (InputStream in = new BufferedInputStream(this.getClass()
.getResourceAsStream(data.name + ".key"))) {
PGPSecretKey secretKey = SecretKeys.readSecretKey(in,
- calculatorProvider, () -> "nonsense".toCharArray(),
+ calculatorProvider,
+ data.encrypted ? () -> "nonsense".toCharArray()
+ : null,
publicKey);
assertNotNull(secretKey);
} catch (PGPException e) {
try {
if (firstChar == '(') {
// Binary format.
- if (!matches(data, 4, PROTECTED_KEY)) {
- // Not encrypted binary format.
- return parser.parseSecretKey(in, null, publicKey);
+ PBEProtectionRemoverFactory decryptor = null;
+ if (matches(data, 4, PROTECTED_KEY)) {
+ // AES/CBC encrypted.
+ decryptor = new JcePBEProtectionRemoverFactory(
+ passphraseSupplier.getPassphrase(),
+ calculatorProvider);
}
- // AES/CBC encrypted.
- PBEProtectionRemoverFactory decryptor = new JcePBEProtectionRemoverFactory(
- passphraseSupplier.getPassphrase(), calculatorProvider);
try (InputStream sIn = new ByteArrayInputStream(data)) {
return parser.parseSecretKey(sIn, decryptor, publicKey);
}