From 37d4d79c64b61eab12d356678e3e1f6151f4e111 Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Wed, 29 Nov 2017 17:29:32 +0000 Subject: [PATCH] Don't rethrow SignatureException as RuntimeException. --- .../bramble/crypto/CryptoComponentImpl.java | 2 +- .../bramble/crypto/EdSignature.java | 42 +++++-------------- .../bramble/crypto/Signature.java | 10 ++--- 3 files changed, 17 insertions(+), 37 deletions(-) diff --git a/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java b/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java index 66f845c31d..e92babdc03 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/crypto/CryptoComponentImpl.java @@ -483,7 +483,7 @@ class CryptoComponentImpl implements CryptoComponent { } private void updateSignature(Signature signature, String label, - byte[] toSign) { + byte[] toSign) throws GeneralSecurityException { byte[] labelBytes = StringUtils.toUtf8(label); byte[] length = new byte[INT_32_BYTES]; ByteUtils.writeUint32(labelBytes.length, length, 0); diff --git a/bramble-core/src/main/java/org/briarproject/bramble/crypto/EdSignature.java b/bramble-core/src/main/java/org/briarproject/bramble/crypto/EdSignature.java index 7d3a658e61..081e810ffa 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/crypto/EdSignature.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/crypto/EdSignature.java @@ -15,7 +15,6 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import java.security.GeneralSecurityException; import java.security.NoSuchAlgorithmException; import java.security.Provider; -import java.security.SignatureException; import static net.i2p.crypto.eddsa.EdDSAEngine.SIGNATURE_ALGORITHM; @@ -57,47 +56,28 @@ class EdSignature implements Signature { } @Override - public void update(byte b) { - try { - signature.update(b); - } catch (SignatureException e) { - throw new RuntimeException(e); - } + public void update(byte b) throws GeneralSecurityException { + signature.update(b); } @Override - public void update(byte[] b) { - try { - signature.update(b); - } catch (SignatureException e) { - throw new RuntimeException(e); - } + public void update(byte[] b) throws GeneralSecurityException { + signature.update(b); } @Override - public void update(byte[] b, int off, int len) { - try { - signature.update(b, off, len); - } catch (SignatureException e) { - throw new RuntimeException(e); - } + public void update(byte[] b, int off, int len) + throws GeneralSecurityException { + signature.update(b, off, len); } @Override - public byte[] sign() { - try { - return signature.sign(); - } catch (SignatureException e) { - throw new RuntimeException(e); - } + public byte[] sign() throws GeneralSecurityException { + return signature.sign(); } @Override - public boolean verify(byte[] sig) { - try { - return signature.verify(sig); - } catch (SignatureException e) { - throw new RuntimeException(e); - } + public boolean verify(byte[] sig) throws GeneralSecurityException { + return signature.verify(sig); } } diff --git a/bramble-core/src/main/java/org/briarproject/bramble/crypto/Signature.java b/bramble-core/src/main/java/org/briarproject/bramble/crypto/Signature.java index f5684a7dd7..5e420ba621 100644 --- a/bramble-core/src/main/java/org/briarproject/bramble/crypto/Signature.java +++ b/bramble-core/src/main/java/org/briarproject/bramble/crypto/Signature.java @@ -22,25 +22,25 @@ interface Signature { /** * @see {@link java.security.Signature#update(byte)} */ - void update(byte b); + void update(byte b) throws GeneralSecurityException; /** * @see {@link java.security.Signature#update(byte[])} */ - void update(byte[] b); + void update(byte[] b) throws GeneralSecurityException; /** * @see {@link java.security.Signature#update(byte[], int, int)} */ - void update(byte[] b, int off, int len); + void update(byte[] b, int off, int len) throws GeneralSecurityException; /** * @see {@link java.security.Signature#sign()} */ - byte[] sign(); + byte[] sign() throws GeneralSecurityException; /** * @see {@link java.security.Signature#verify(byte[])} */ - boolean verify(byte[] signature); + boolean verify(byte[] signature) throws GeneralSecurityException; } -- GitLab