1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 22:32:07 +01:00

Remove more unused methods and fix method name

This commit is contained in:
Paul Schaub 2021-06-28 21:14:40 +02:00
parent 02ddb71c07
commit dff47d17d1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 14 additions and 22 deletions

View file

@ -276,7 +276,7 @@ public abstract class SignatureValidator {
@Override
public void verify(PGPSignature signature) throws SignatureValidationException {
PublicKeyAlgorithm algorithm = PublicKeyAlgorithm.fromId(signingKey.getAlgorithm());
int bitStrength = BCUtil.getBitStrenght(signingKey);
int bitStrength = BCUtil.getBitStrength(signingKey);
if (!policy.getPublicKeyAlgorithmPolicy().isAcceptable(algorithm, bitStrength)) {
throw new SignatureValidationException("Signature was made using unacceptable key. " +
algorithm + " (" + bitStrength + " bits) is not acceptable according to the public key algorithm policy.");

View file

@ -15,29 +15,21 @@
*/
package org.pgpainless.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.Nonnull;
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.bcpg.ECPublicBCPGKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPUtil;
public class BCUtil {
public static InputStream getPgpDecoderInputStream(@Nonnull byte[] bytes)
throws IOException {
return getPgpDecoderInputStream(new ByteArrayInputStream(bytes));
}
public static InputStream getPgpDecoderInputStream(@Nonnull InputStream inputStream)
throws IOException {
return PGPUtil.getDecoderStream(inputStream);
}
public static int getBitStrenght(PGPPublicKey key) {
/**
* Utility method to get the bit strength of OpenPGP keys.
* Bouncycastle is lacking support for some keys (eg. EdDSA, X25519), so this method
* manually derives the bit strength from the keys curves OID.
*
* @param key key
* @return bit strength
*/
public static int getBitStrength(PGPPublicKey key) {
int bitStrength = key.getBitStrength();
if (bitStrength == -1) {

View file

@ -116,22 +116,22 @@ public class BrainpoolKeyGenerationTest {
PGPSecretKey ecdsaPrim = iterator.next();
KeyInfo ecdsaInfo = new KeyInfo(ecdsaPrim);
assertEquals(EllipticCurve._BRAINPOOLP384R1.getName(), ecdsaInfo.getCurveName());
assertEquals(384, BCUtil.getBitStrenght(ecdsaPrim.getPublicKey()));
assertEquals(384, BCUtil.getBitStrength(ecdsaPrim.getPublicKey()));
PGPSecretKey eddsaSub = iterator.next();
KeyInfo eddsaInfo = new KeyInfo(eddsaSub);
assertEquals(EdDSACurve._Ed25519.getName(), eddsaInfo.getCurveName());
assertEquals(256, BCUtil.getBitStrenght(eddsaSub.getPublicKey()));
assertEquals(256, BCUtil.getBitStrength(eddsaSub.getPublicKey()));
PGPSecretKey xdhSub = iterator.next();
KeyInfo xdhInfo = new KeyInfo(xdhSub);
assertEquals(XDHSpec._X25519.getCurveName(), xdhInfo.getCurveName());
assertEquals(256, BCUtil.getBitStrenght(xdhSub.getPublicKey()));
assertEquals(256, BCUtil.getBitStrength(xdhSub.getPublicKey()));
PGPSecretKey rsaSub = iterator.next();
KeyInfo rsaInfo = new KeyInfo(rsaSub);
assertThrows(IllegalArgumentException.class, rsaInfo::getCurveName, "RSA is not a curve-based encryption system");
assertEquals(3072, BCUtil.getBitStrenght(rsaSub.getPublicKey()));
assertEquals(3072, BCUtil.getBitStrength(rsaSub.getPublicKey()));
}
public PGPSecretKeyRing generateKey(KeySpec primaryKey, KeySpec subKey, String userId) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {