Remove unused PGP signature artefacts from PGPAuthenticationSignatureGenerator
This commit is contained in:
@@ -3,12 +3,10 @@ package org.bouncycastle.openpgp;
|
|||||||
import org.bouncycastle.bcpg.MPInteger;
|
import org.bouncycastle.bcpg.MPInteger;
|
||||||
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
|
import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
|
||||||
import org.bouncycastle.bcpg.SignaturePacket;
|
import org.bouncycastle.bcpg.SignaturePacket;
|
||||||
import org.bouncycastle.bcpg.SignatureSubpacket;
|
|
||||||
import org.bouncycastle.openpgp.operator.PGPContentSigner;
|
import org.bouncycastle.openpgp.operator.PGPContentSigner;
|
||||||
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder;
|
||||||
import org.bouncycastle.util.BigIntegers;
|
import org.bouncycastle.util.BigIntegers;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
@@ -22,8 +20,6 @@ public class PGPAuthenticationSignatureGenerator
|
|||||||
private PGPContentSignerBuilder contentSignerBuilder;
|
private PGPContentSignerBuilder contentSignerBuilder;
|
||||||
private PGPContentSigner contentSigner;
|
private PGPContentSigner contentSigner;
|
||||||
private int sigType;
|
private int sigType;
|
||||||
private byte lastb;
|
|
||||||
private int providedKeyAlgorithm = -1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a signature generator built on the passed in contentSignerBuilder.
|
* Create a signature generator built on the passed in contentSignerBuilder.
|
||||||
@@ -51,49 +47,18 @@ public class PGPAuthenticationSignatureGenerator
|
|||||||
contentSigner = contentSignerBuilder.build(signatureType, key);
|
contentSigner = contentSignerBuilder.build(signatureType, key);
|
||||||
sigOut = contentSigner.getOutputStream();
|
sigOut = contentSigner.getOutputStream();
|
||||||
sigType = contentSigner.getType();
|
sigType = contentSigner.getType();
|
||||||
lastb = 0;
|
|
||||||
|
|
||||||
if (providedKeyAlgorithm >= 0 && providedKeyAlgorithm != contentSigner.getKeyAlgorithm())
|
|
||||||
{
|
|
||||||
throw new PGPException("key algorithm mismatch");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(
|
public void update(
|
||||||
byte b)
|
byte b)
|
||||||
{
|
{
|
||||||
if (sigType == PGPSignature.CANONICAL_TEXT_DOCUMENT)
|
byteUpdate(b);
|
||||||
{
|
|
||||||
if (b == '\r')
|
|
||||||
{
|
|
||||||
byteUpdate((byte)'\r');
|
|
||||||
byteUpdate((byte)'\n');
|
|
||||||
}
|
|
||||||
else if (b == '\n')
|
|
||||||
{
|
|
||||||
if (lastb != '\r')
|
|
||||||
{
|
|
||||||
byteUpdate((byte)'\r');
|
|
||||||
byteUpdate((byte)'\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
byteUpdate(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastb = b;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
byteUpdate(b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(
|
public void update(
|
||||||
byte[] b)
|
byte[] b)
|
||||||
{
|
{
|
||||||
this.update(b, 0, b.length);
|
update(b, 0, b.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(
|
public void update(
|
||||||
@@ -101,19 +66,8 @@ public class PGPAuthenticationSignatureGenerator
|
|||||||
int off,
|
int off,
|
||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
if (sigType == PGPSignature.CANONICAL_TEXT_DOCUMENT)
|
|
||||||
{
|
|
||||||
int finish = off + len;
|
|
||||||
|
|
||||||
for (int i = off; i != finish; i++)
|
blockUpdate(b, off, len);
|
||||||
{
|
|
||||||
this.update(b[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
blockUpdate(b, off, len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void byteUpdate(byte b)
|
private void byteUpdate(byte b)
|
||||||
@@ -150,25 +104,6 @@ public class PGPAuthenticationSignatureGenerator
|
|||||||
throws PGPException
|
throws PGPException
|
||||||
{
|
{
|
||||||
MPInteger[] sigValues;
|
MPInteger[] sigValues;
|
||||||
ByteArrayOutputStream sOut = new ByteArrayOutputStream();
|
|
||||||
SignatureSubpacket[] hPkts, unhPkts;
|
|
||||||
hPkts = new SignatureSubpacket[0];
|
|
||||||
unhPkts = new SignatureSubpacket[0];
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ByteArrayOutputStream hOut = new ByteArrayOutputStream();
|
|
||||||
byte[] data = hOut.toByteArray();
|
|
||||||
sOut.write(data);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
throw new PGPException("exception encoding hashed data.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] trailer = sOut.toByteArray();
|
|
||||||
|
|
||||||
blockUpdate(trailer, 0, trailer.length);
|
|
||||||
|
|
||||||
if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN
|
if (contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_SIGN
|
||||||
|| contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) // an RSA signature
|
|| contentSigner.getKeyAlgorithm() == PublicKeyAlgorithmTags.RSA_GENERAL) // an RSA signature
|
||||||
@@ -190,12 +125,7 @@ public class PGPAuthenticationSignatureGenerator
|
|||||||
sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature());
|
sigValues = PGPUtil.dsaSigToMpi(contentSigner.getSignature());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] digest = contentSigner.getDigest();
|
return new PGPSignature(new SignaturePacket(sigType, contentSigner.getKeyID(), contentSigner.getKeyAlgorithm(),
|
||||||
byte[] fingerPrint = new byte[2];
|
contentSigner.getHashAlgorithm(), null, null, null, sigValues));
|
||||||
|
|
||||||
fingerPrint[0] = digest[0];
|
|
||||||
fingerPrint[1] = digest[1];
|
|
||||||
|
|
||||||
return new PGPSignature(new SignaturePacket(sigType, contentSigner.getKeyID(), contentSigner.getKeyAlgorithm(), contentSigner.getHashAlgorithm(), hPkts, unhPkts, fingerPrint, sigValues));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user