From c8e290b015e1619c9c12814d6eb79f23347a589a Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 4 Apr 2024 14:39:25 +0200 Subject: [PATCH] Tests: Read secret key from rpm/test/resources --- .../pgpainless/AbstractSigningTest.java | 135 ++---------------- 1 file changed, 11 insertions(+), 124 deletions(-) diff --git a/pgpainless/src/test/java/org/eclipse/packager/rpm/signature/pgpainless/AbstractSigningTest.java b/pgpainless/src/test/java/org/eclipse/packager/rpm/signature/pgpainless/AbstractSigningTest.java index 268631c..8bf0584 100644 --- a/pgpainless/src/test/java/org/eclipse/packager/rpm/signature/pgpainless/AbstractSigningTest.java +++ b/pgpainless/src/test/java/org/eclipse/packager/rpm/signature/pgpainless/AbstractSigningTest.java @@ -6,136 +6,23 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.bc.BcPGPObjectFactory; -import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; -import java.nio.charset.StandardCharsets; public class AbstractSigningTest { - public static final String KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + - "Version: OpenPGP.js v4.10.10\n" + - "Comment: https://openpgpjs.org\n" + - "\n" + - "xcaGBGQAqhABEAC5XnVvJlEeArPCduQlVs+ekqIYOTJP40ShB7EOnM3N6ep8\n" + - "nzYvcYfuxh+cO8DO/C71AEvs9YnHnoZwUX/ki31d1tOzW6LLsuspQqHZUXH2\n" + - "HQsm8ph5hCQi/Cx50Ym22LXYI7Dkg18xEVJK+np6p9cR/grQfprXbGeJxc1v\n" + - "tdNJZNp4p9txlwNLMGi7cVxebn3WFMieXdwx9qPrZHob+r7r/Jm0ORUvPHRz\n" + - "Q8SLR1SxpaUm1EVZKu6A8sQ8GLgqLtm4PZtUznucMZN5Vntn9OthSPXtfw7L\n" + - "Z6jERwrSw9B9k8cRvOws1CFIDMzZwz8GXwa9QRQUF0doOCKW/MEX0h8q+B8i\n" + - "kkWvpKKzYe8lGsuiXDjfiXg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1GaDTuEWE/GJxSihblg6VfQAU0SsZyipHrn8IE2AKbs\n" + - "ic5pJImMftJDfc3+0ETsjl3YYfAr3c/GgdJ1igzV4Oh2usp6WrzjxhebaiJq\n" + - "goYgB4k+Ka4HZgErvtDCUYsZFzdx+pYOmPfZbcmQRigot3gFbpH/+vJmdTgT\n" + - "s4+7rSvSKXdY89W+idL0VXWBr3+JOi3b27p1nWZGvYnNQ3FuRqDv+LF9gkQu\n" + - "HzhM+ElV1QtvSef6ewobxniLmPCifprFkkQz633hItACudBqR5zj+nktn4Pi\n" + - "M9NpcU44xdtvK347CZ8khYof+vkAWISVpie34C3rUNETMAikRkXhnU74tO2B\n" + - "25uiY4mR\n" + - "=iZMt\n" + - "-----END PGP PRIVATE KEY BLOCK-----"; - public static final char[] PASSPHRASE = "testkey".toCharArray(); public PGPSecretKeyRing readSecretKey() throws IOException { - ByteArrayInputStream bIn = new ByteArrayInputStream(KEY.getBytes(StandardCharsets.UTF_8)); - ArmoredInputStream armorIn = new ArmoredInputStream(bIn); - BCPGInputStream bcIn = new BCPGInputStream(armorIn); - PGPObjectFactory objectFactory = new BcPGPObjectFactory(bcIn); - return (PGPSecretKeyRing) objectFactory.nextObject(); + File keyFile = new File("../rpm/src/test/resources/key/private_key.txt"); + try ( + FileInputStream fileIn = new FileInputStream(keyFile); + ArmoredInputStream armorIn = new ArmoredInputStream(fileIn); + BCPGInputStream bcIn = new BCPGInputStream(armorIn) + ) { + PGPObjectFactory objectFactory = new BcPGPObjectFactory(bcIn); + return (PGPSecretKeyRing) objectFactory.nextObject(); + } } }