1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-18 02:12:06 +01:00

KeyRingReader: Remove unused @throws IOException

This commit is contained in:
Paul Schaub 2023-05-03 17:23:13 +02:00
parent fb581f11c7
commit 005b9d477a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
8 changed files with 14 additions and 25 deletions

View file

@ -4,9 +4,9 @@
package org.pgpainless.encryption_signing; package org.pgpainless.encryption_signing;
import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.MessageDigest; import java.security.MessageDigest;
import javax.annotation.Nonnull;
import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.Signer; import org.bouncycastle.crypto.Signer;
@ -23,18 +23,15 @@ abstract class PGPHashContextContentSignerBuilder implements PGPContentSignerBui
this.sig = sig; this.sig = sig;
} }
public void write(byte[] bytes, int off, int len) public void write(@Nonnull byte[] bytes, int off, int len) {
throws IOException {
sig.update(bytes, off, len); sig.update(bytes, off, len);
} }
public void write(byte[] bytes) public void write(@Nonnull byte[] bytes) {
throws IOException {
sig.update(bytes, 0, bytes.length); sig.update(bytes, 0, bytes.length);
} }
public void write(int b) public void write(int b) {
throws IOException {
sig.update((byte) b); sig.update((byte) b);
} }
} }

View file

@ -188,7 +188,7 @@ public interface SecretKeyRingEditorInterface {
@Nonnull SecretKeyRingProtector primaryKeyProtector, @Nonnull SecretKeyRingProtector primaryKeyProtector,
@Nonnull KeyFlag keyFlag, @Nonnull KeyFlag keyFlag,
KeyFlag... additionalKeyFlags) KeyFlag... additionalKeyFlags)
throws PGPException, IOException, NoSuchAlgorithmException; throws PGPException, IOException;
/** /**
* Revoke the key ring. * Revoke the key ring.

View file

@ -88,12 +88,12 @@ public class KeyRingReader {
} }
public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull InputStream inputStream) public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException, PGPException { throws IOException {
return readPublicKeyRingCollection(inputStream); return readPublicKeyRingCollection(inputStream);
} }
public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull byte[] bytes) public PGPPublicKeyRingCollection publicKeyRingCollection(@Nonnull byte[] bytes)
throws IOException, PGPException { throws IOException {
return publicKeyRingCollection(new ByteArrayInputStream(bytes)); return publicKeyRingCollection(new ByteArrayInputStream(bytes));
} }
@ -118,17 +118,17 @@ public class KeyRingReader {
} }
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull InputStream inputStream) public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull InputStream inputStream)
throws IOException, PGPException { throws IOException {
return readSecretKeyRingCollection(inputStream); return readSecretKeyRingCollection(inputStream);
} }
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull byte[] bytes) public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull byte[] bytes)
throws IOException, PGPException { throws IOException {
return secretKeyRingCollection(new ByteArrayInputStream(bytes)); return secretKeyRingCollection(new ByteArrayInputStream(bytes));
} }
public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull String asciiArmored) public PGPSecretKeyRingCollection secretKeyRingCollection(@Nonnull String asciiArmored)
throws IOException, PGPException { throws IOException {
return secretKeyRingCollection(asciiArmored.getBytes(UTF8)); return secretKeyRingCollection(asciiArmored.getBytes(UTF8));
} }

View file

@ -243,7 +243,7 @@ public final class SignatureUtils {
* @throws IOException in case of a stream error * @throws IOException in case of a stream error
* @throws PGPException in case of an OpenPGP error * @throws PGPException in case of an OpenPGP error
*/ */
public static List<PGPSignature> readSignatures(InputStream inputStream, int maxIterations) throws IOException, PGPException { public static List<PGPSignature> readSignatures(InputStream inputStream, int maxIterations) throws IOException {
List<PGPSignature> signatures = new ArrayList<>(); List<PGPSignature> signatures = new ArrayList<>();
InputStream pgpIn = ArmorUtils.getDecoderStream(inputStream); InputStream pgpIn = ArmorUtils.getDecoderStream(inputStream);
PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(pgpIn); PGPObjectFactory objectFactory = ImplementationFactory.getInstance().getPGPObjectFactory(pgpIn);

View file

@ -7,8 +7,6 @@ package org.bouncycastle;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPPrivateKey;
@ -25,8 +23,6 @@ import org.pgpainless.key.info.KeyRingInfo;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import org.pgpainless.key.protection.UnlockSecretKey; import org.pgpainless.key.protection.UnlockSecretKey;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class CachingBcPublicKeyDataDecryptorFactoryTest { public class CachingBcPublicKeyDataDecryptorFactoryTest {
private static final String KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" + private static final String KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n" +
@ -64,7 +60,7 @@ public class CachingBcPublicKeyDataDecryptorFactoryTest {
"-----END PGP MESSAGE-----"; "-----END PGP MESSAGE-----";
@Test @Test
public void test() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { public void test() throws PGPException, IOException {
PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY); PGPSecretKeyRing secretKeys = PGPainless.readKeyRing().secretKeyRing(KEY);
SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys(); SecretKeyRingProtector protector = SecretKeyRingProtector.unprotectedKeys();
KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys); KeyRingInfo info = PGPainless.inspectKeyRing(secretKeys);

View file

@ -56,7 +56,7 @@ public class PGPKeyRingCollectionTest {
} }
@Test @Test
public void testConstructorFromCollection() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, IOException { public void testConstructorFromCollection() throws PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException {
PGPSecretKeyRing first = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit"); PGPSecretKeyRing first = PGPainless.generateKeyRing().simpleEcKeyRing("alice@wonderland.lit");
PGPSecretKeyRing second = PGPainless.generateKeyRing().simpleEcKeyRing("bob@the-builder.tv"); PGPSecretKeyRing second = PGPainless.generateKeyRing().simpleEcKeyRing("bob@the-builder.tv");
PGPPublicKeyRing secondPub = KeyRingUtils.publicKeyRingFrom(second); PGPPublicKeyRing secondPub = KeyRingUtils.publicKeyRingFrom(second);

View file

@ -113,7 +113,7 @@ public class EncryptImpl implements Encrypt {
encryptionOptions.addRecipients(certificates); encryptionOptions.addRecipients(certificates);
} catch (KeyException.UnacceptableEncryptionKeyException e) { } catch (KeyException.UnacceptableEncryptionKeyException e) {
throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e); throw new SOPGPException.CertCannotEncrypt(e.getMessage(), e);
} catch (IOException | PGPException e) { } catch (IOException e) {
throw new SOPGPException.BadData(e); throw new SOPGPException.BadData(e);
} }
return this; return this;

View file

@ -33,8 +33,6 @@ class KeyReader {
throw new SOPGPException.BadData(e); throw new SOPGPException.BadData(e);
} }
throw e; throw e;
} catch (PGPException e) {
throw new SOPGPException.BadData("Cannot read keys.", e);
} }
if (requireContent && (keys == null || keys.size() == 0)) { if (requireContent && (keys == null || keys.size() == 0)) {
@ -54,8 +52,6 @@ class KeyReader {
throw new SOPGPException.BadData(e); throw new SOPGPException.BadData(e);
} }
throw e; throw e;
} catch (PGPException e) {
throw new SOPGPException.BadData(e);
} }
if (requireContent && (certs == null || certs.size() == 0)) { if (requireContent && (certs == null || certs.size() == 0)) {
throw new SOPGPException.BadData(new PGPException("No cert data found.")); throw new SOPGPException.BadData(new PGPException("No cert data found."));