From 2e3649100c215584029427a087b066b16bda0d88 Mon Sep 17 00:00:00 2001 From: Christian Hagau Date: Sun, 12 Nov 2017 00:00:00 +0000 Subject: [PATCH] Rename PGPAuthenticationSignatureGenerator to AuthenticationSignatureGenerator & reformat --- .../keychain/pgp/CanonicalizedSecretKey.java | 8 +- .../keychain/ssh/AuthenticationOperation.java | 4 +- ... => AuthenticationSignatureGenerator.java} | 77 ++++++------------- 3 files changed, 29 insertions(+), 60 deletions(-) rename libkeychain/src/main/java/org/bouncycastle/openpgp/{PGPAuthenticationSignatureGenerator.java => AuthenticationSignatureGenerator.java} (64%) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 4d01257cd..48974ef17 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -28,7 +28,7 @@ import java.util.Map; import org.bouncycastle.bcpg.S2K; import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; -import org.bouncycastle.openpgp.PGPAuthenticationSignatureGenerator; +import org.bouncycastle.openpgp.AuthenticationSignatureGenerator; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPPrivateKey; import org.bouncycastle.openpgp.PGPSecretKey; @@ -253,8 +253,8 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { } } - public PGPAuthenticationSignatureGenerator getAuthenticationSignatureGenerator(int hashAlgorithm, - Map signedHashes) + public AuthenticationSignatureGenerator getAuthenticationSignatureGenerator(int hashAlgorithm, + Map signedHashes) throws PgpGeneralException { if (mPrivateKeyState == PRIVATE_KEY_STATE_LOCKED) { throw new PrivateKeyNotUnlockedException(); @@ -263,7 +263,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { PGPContentSignerBuilder contentSignerBuilder = getContentSignerBuilder(hashAlgorithm, signedHashes); try { - PGPAuthenticationSignatureGenerator signatureGenerator = new PGPAuthenticationSignatureGenerator(contentSignerBuilder); + AuthenticationSignatureGenerator signatureGenerator = new AuthenticationSignatureGenerator(contentSignerBuilder); signatureGenerator.init(PGPSignature.BINARY_DOCUMENT, mPrivateKey); return signatureGenerator; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ssh/AuthenticationOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ssh/AuthenticationOperation.java index 174efc4da..d30f305b1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ssh/AuthenticationOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ssh/AuthenticationOperation.java @@ -19,7 +19,7 @@ package org.sufficientlysecure.keychain.ssh; import android.content.Context; import android.support.annotation.NonNull; -import org.bouncycastle.openpgp.PGPAuthenticationSignatureGenerator; +import org.bouncycastle.openpgp.AuthenticationSignatureGenerator; import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.operator.jcajce.NfcSyncPGPContentSignerBuilder; import org.sufficientlysecure.keychain.operations.BaseOperation; @@ -206,7 +206,7 @@ public class AuthenticationOperation extends BaseOperation } - PGPAuthenticationSignatureGenerator signatureGenerator; + AuthenticationSignatureGenerator signatureGenerator; try { signatureGenerator = authKey.getAuthenticationSignatureGenerator( hashAlgorithm, cryptoInput.getCryptoData()); diff --git a/libkeychain/src/main/java/org/bouncycastle/openpgp/PGPAuthenticationSignatureGenerator.java b/libkeychain/src/main/java/org/bouncycastle/openpgp/AuthenticationSignatureGenerator.java similarity index 64% rename from libkeychain/src/main/java/org/bouncycastle/openpgp/PGPAuthenticationSignatureGenerator.java rename to libkeychain/src/main/java/org/bouncycastle/openpgp/AuthenticationSignatureGenerator.java index 8c170d045..cb36576f4 100644 --- a/libkeychain/src/main/java/org/bouncycastle/openpgp/PGPAuthenticationSignatureGenerator.java +++ b/libkeychain/src/main/java/org/bouncycastle/openpgp/AuthenticationSignatureGenerator.java @@ -12,23 +12,20 @@ import java.io.OutputStream; import java.math.BigInteger; /** - * Generator for PGP Signatures. + * Generator for authentication signatures. */ -public class PGPAuthenticationSignatureGenerator -{ +public class AuthenticationSignatureGenerator { private OutputStream sigOut; private PGPContentSignerBuilder contentSignerBuilder; private PGPContentSigner contentSigner; - private int sigType; + private int sigType; /** * Create a signature generator built on the passed in contentSignerBuilder. * - * @param contentSignerBuilder builder to produce PGPContentSigner objects for generating signatures. + * @param contentSignerBuilder builder to produce PGPContentSigner objects for generating signatures. */ - public PGPAuthenticationSignatureGenerator( - PGPContentSignerBuilder contentSignerBuilder) - { + public AuthenticationSignatureGenerator(PGPContentSignerBuilder contentSignerBuilder) { this.contentSignerBuilder = contentSignerBuilder; } @@ -39,89 +36,61 @@ public class PGPAuthenticationSignatureGenerator * @param key * @throws PGPException */ - public void init( - int signatureType, - PGPPrivateKey key) - throws PGPException - { + public void init(int signatureType, PGPPrivateKey key) throws PGPException { contentSigner = contentSignerBuilder.build(signatureType, key); sigOut = contentSigner.getOutputStream(); sigType = contentSigner.getType(); } - - public void update( - byte b) - { + + public void update(byte b) { byteUpdate(b); } - - public void update( - byte[] b) - { + + public void update(byte[] b) { update(b, 0, b.length); } - - public void update( - byte[] b, - int off, - int len) - { + public void update(byte[] b, int off, int len) { blockUpdate(b, off, len); } - private void byteUpdate(byte b) - { - try - { + private void byteUpdate(byte b) { + try { sigOut.write(b); - } - catch (IOException e) - { + } catch (IOException e) { throw new PGPRuntimeOperationException(e.getMessage(), e); } } - private void blockUpdate(byte[] block, int off, int len) - { - try - { + private void blockUpdate(byte[] block, int off, int len) { + try { sigOut.write(block, off, len); - } - catch (IOException e) - { + } catch (IOException e) { throw new PGPRuntimeOperationException(e.getMessage(), e); } } /** * Return a signature object containing the current signature state. - * + * * @return PGPSignature * @throws PGPException */ - public PGPSignature generate() - throws PGPException - { - MPInteger[] sigValues; + public PGPSignature generate() throws PGPException { + MPInteger[] sigValues; if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN - || contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) // an RSA signature - { + || contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) { sigValues = new MPInteger[1]; sigValues[0] = new MPInteger(new BigInteger(1, contentSigner.getSignature())); - } - else if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA) - { + } else if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.EDDSA) { byte[] sig = contentSigner.getSignature(); sigValues = new MPInteger[2]; sigValues[0] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 0, 32)); sigValues[1] = new MPInteger(BigIntegers.fromUnsignedByteArray(sig, 32, 32)); - } - else - { + } else { sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature()); }