Rename PGPAuthenticationSignatureGenerator to

AuthenticationSignatureGenerator & reformat
This commit is contained in:
Christian Hagau
2017-11-12 00:00:00 +00:00
parent 48b8f97b78
commit 2e3649100c
3 changed files with 29 additions and 60 deletions

View File

@@ -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());
}