1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 06:11:08 +01:00

Remove deprecated class PGPKeyRing

This commit is contained in:
Paul Schaub 2020-12-08 19:14:52 +01:00
parent e535bd2f55
commit 980782e629
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
11 changed files with 91 additions and 247 deletions

View file

@ -1,77 +0,0 @@
/*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.collection;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.pgpainless.key.OpenPgpV4Fingerprint;
@Deprecated
public class PGPKeyRing {
private PGPPublicKeyRing publicKeys;
private PGPSecretKeyRing secretKeys;
public PGPKeyRing(@Nonnull PGPPublicKeyRing publicKeys, @Nonnull PGPSecretKeyRing secretKeys) {
if (publicKeys.getPublicKey().getKeyID() != secretKeys.getPublicKey().getKeyID()) {
throw new IllegalArgumentException("publicKeys and secretKeys must have the same master key.");
}
this.publicKeys = publicKeys;
this.secretKeys = secretKeys;
}
public PGPKeyRing(@Nonnull PGPPublicKeyRing publicKeys) {
this.publicKeys = publicKeys;
}
public PGPKeyRing(@Nonnull PGPSecretKeyRing secretKeys) {
this.secretKeys = secretKeys;
}
public long getKeyId() {
return getMasterKey().getKeyID();
}
public @Nonnull PGPPublicKey getMasterKey() {
PGPPublicKey publicKey = hasSecretKeys() ? secretKeys.getPublicKey() : publicKeys.getPublicKey();
if (!publicKey.isMasterKey()) {
throw new IllegalStateException("Expected master key is not a master key");
}
return publicKey;
}
public @Nonnull OpenPgpV4Fingerprint getV4Fingerprint() {
return new OpenPgpV4Fingerprint(getMasterKey());
}
public boolean hasSecretKeys() {
return secretKeys != null;
}
public @Nullable PGPPublicKeyRing getPublicKeys() {
return publicKeys;
}
public @Nullable PGPSecretKeyRing getSecretKeys() {
return secretKeys;
}
}

View file

@ -35,7 +35,6 @@ import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPKeyRingGenerator;
import org.bouncycastle.openpgp.PGPPrivateKey;
import org.bouncycastle.openpgp.PGPPublicKey;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKey;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSignature;
@ -53,7 +52,6 @@ import org.bouncycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.algorithm.KeyFlag;
import org.pgpainless.algorithm.SignatureType;
import org.pgpainless.key.collection.PGPKeyRing;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.curve.EllipticCurve;
import org.pgpainless.key.generation.type.length.RsaLength;
@ -70,7 +68,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
private Set<String> additionalUserIds = new LinkedHashSet<>();
private Passphrase passphrase;
public PGPKeyRing simpleRsaKeyRing(@Nonnull UserId userId, @Nonnull RsaLength length)
public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull UserId userId, @Nonnull RsaLength length)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleRsaKeyRing(userId.toString(), length);
}
@ -84,12 +82,12 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
*
* @return {@link PGPSecretKeyRing} containing the KeyPair.
*/
public PGPKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length)
public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleRsaKeyRing(userId, length, null);
}
public PGPKeyRing simpleRsaKeyRing(@Nonnull UserId userId, @Nonnull RsaLength rsaLength, String password)
public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull UserId userId, @Nonnull RsaLength rsaLength, String password)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleRsaKeyRing(userId.toString(), rsaLength, password);
}
@ -104,7 +102,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
*
* @return {@link PGPSecretKeyRing} containing the KeyPair.
*/
public PGPKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length, String password)
public PGPSecretKeyRing simpleRsaKeyRing(@Nonnull String userId, @Nonnull RsaLength length, String password)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
WithAdditionalUserIdOrPassphrase builder = this
.withMasterKey(
@ -120,7 +118,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
}
}
public PGPKeyRing simpleEcKeyRing(@Nonnull UserId userId)
public PGPSecretKeyRing simpleEcKeyRing(@Nonnull UserId userId)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleEcKeyRing(userId.toString());
}
@ -134,12 +132,12 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
*
* @return {@link PGPSecretKeyRing} containing the key pairs.
*/
public PGPKeyRing simpleEcKeyRing(@Nonnull String userId)
public PGPSecretKeyRing simpleEcKeyRing(@Nonnull String userId)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleEcKeyRing(userId, null);
}
public PGPKeyRing simpleEcKeyRing(@Nonnull UserId userId, String password)
public PGPSecretKeyRing simpleEcKeyRing(@Nonnull UserId userId, String password)
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException {
return simpleEcKeyRing(userId.toString(), password);
}
@ -154,7 +152,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
*
* @return {@link PGPSecretKeyRing} containing the key pairs.
*/
public PGPKeyRing simpleEcKeyRing(@Nonnull String userId, String password)
public PGPSecretKeyRing simpleEcKeyRing(@Nonnull String userId, String password)
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
WithAdditionalUserIdOrPassphrase builder = this
.withSubKey(
@ -249,7 +247,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
private PBESecretKeyEncryptor secretKeyEncryptor;
@Override
public PGPKeyRing build() throws NoSuchAlgorithmException, PGPException,
public PGPSecretKeyRing build() throws NoSuchAlgorithmException, PGPException,
InvalidAlgorithmParameterException {
digestCalculator = buildDigestCalculator();
secretKeyEncryptor = buildSecretKeyEncryptor();
@ -300,15 +298,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
}
secretKeyRing = new PGPSecretKeyRing(secretKeyList);
// extract public key ring from secret keys
List<PGPPublicKey> publicKeyList = new ArrayList<>();
Iterator<PGPPublicKey> publicKeys = secretKeyRing.getPublicKeys();
while (publicKeys.hasNext()) {
publicKeyList.add(publicKeys.next());
}
PGPPublicKeyRing publicKeyRing = new PGPPublicKeyRing(publicKeyList);
return new PGPKeyRing(publicKeyRing, secretKeyRing);
return secretKeyRing;
}
private PGPKeyRingGenerator buildRingGenerator(PGPKeyPair certKey,

View file

@ -15,12 +15,12 @@
*/
package org.pgpainless.key.generation;
import javax.annotation.Nonnull;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPException;
import org.pgpainless.key.collection.PGPKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.pgpainless.key.util.UserId;
import org.pgpainless.util.Passphrase;
@ -59,8 +59,7 @@ public interface KeyRingBuilderInterface {
interface Build {
PGPKeyRing build() throws NoSuchAlgorithmException, PGPException,
PGPSecretKeyRing build() throws NoSuchAlgorithmException, PGPException,
InvalidAlgorithmParameterException;
}
}

View file

@ -15,12 +15,11 @@
*/
package org.pgpainless.key.parsing;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import javax.annotation.Nonnull;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing;
@ -29,7 +28,6 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
import org.pgpainless.key.collection.PGPKeyRing;
public class KeyRingReader {
@ -85,27 +83,6 @@ public class KeyRingReader {
return secretKeyRingCollection(asciiArmored.getBytes(UTF8));
}
@Deprecated
public PGPKeyRing keyRing(@Nullable InputStream publicIn, @Nullable InputStream secretIn) throws IOException, PGPException {
return readKeyRing(publicIn, secretIn);
}
@Deprecated
public PGPKeyRing keyRing(@Nullable byte[] publicBytes, @Nullable byte[] secretBytes) throws IOException, PGPException {
return keyRing(
publicBytes != null ? new ByteArrayInputStream(publicBytes) : null,
secretBytes != null ? new ByteArrayInputStream(secretBytes) : null
);
}
@Deprecated
public PGPKeyRing keyRing(@Nullable String asciiPublic, @Nullable String asciiSecret) throws IOException, PGPException {
return keyRing(
asciiPublic != null ? asciiPublic.getBytes(UTF8) : null,
asciiSecret != null ? asciiSecret.getBytes(UTF8) : null
);
}
/*
STATIC METHODS
*/
@ -136,16 +113,6 @@ public class KeyRingReader {
new BcKeyFingerprintCalculator());
}
@Deprecated
public static PGPKeyRing readKeyRing(@Nullable InputStream publicIn, @Nullable InputStream secretIn) throws IOException, PGPException {
validateStreamsNotBothNull(publicIn, secretIn);
PGPPublicKeyRing publicKeys = maybeReadPublicKeys(publicIn);
PGPSecretKeyRing secretKeys = maybeReadSecretKeys(secretIn);
return asPGPKeyRing(publicKeys, secretKeys);
}
private static void validateStreamsNotBothNull(InputStream publicIn, InputStream secretIn) {
if (publicIn == null && secretIn == null) {
throw new NullPointerException("publicIn and secretIn cannot be BOTH null.");
@ -165,15 +132,4 @@ public class KeyRingReader {
}
return null;
}
@Deprecated
private static PGPKeyRing asPGPKeyRing(PGPPublicKeyRing publicKeys, PGPSecretKeyRing secretKeys) {
if (secretKeys == null) {
return new PGPKeyRing(publicKeys);
}
if (publicKeys == null) {
return new PGPKeyRing(secretKeys);
}
return new PGPKeyRing(publicKeys, secretKeys);
}
}