From 6f0cf35e318b7beaa56ed2e8bd1f16ab700520e7 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Fri, 28 May 2021 21:33:20 +0200 Subject: [PATCH] Delete redundant classes --- .../exception/SecretKeyNotFoundException.java | 32 ---------- .../java/org/pgpainless/key/KeyValidator.java | 59 ------------------- .../PassphraseMapKeyRingProtector.java | 35 ----------- .../org/pgpainless/util/SignatureTree.java | 35 ----------- .../main/java/org/pgpainless/util/Tuple.java | 34 ----------- 5 files changed, 195 deletions(-) delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/exception/SecretKeyNotFoundException.java delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/key/KeyValidator.java delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/key/protection/PassphraseMapKeyRingProtector.java delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/util/SignatureTree.java delete mode 100644 pgpainless-core/src/main/java/org/pgpainless/util/Tuple.java diff --git a/pgpainless-core/src/main/java/org/pgpainless/exception/SecretKeyNotFoundException.java b/pgpainless-core/src/main/java/org/pgpainless/exception/SecretKeyNotFoundException.java deleted file mode 100644 index 61966203..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/exception/SecretKeyNotFoundException.java +++ /dev/null @@ -1,32 +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.exception; - -public class SecretKeyNotFoundException extends Exception { - - private static final long serialVersionUID = 1L; - - private long keyId; - - public SecretKeyNotFoundException(long keyId) { - super("No PGPSecretKey with id " + Long.toHexString(keyId) + " (" + keyId + ") found."); - this.keyId = keyId; - } - - public long getKeyId() { - return keyId; - } -} diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/KeyValidator.java b/pgpainless-core/src/main/java/org/pgpainless/key/KeyValidator.java deleted file mode 100644 index f5be11f0..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/key/KeyValidator.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2021 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; - -import java.util.Iterator; - -import org.bouncycastle.openpgp.PGPException; -import org.bouncycastle.openpgp.PGPPublicKey; -import org.bouncycastle.openpgp.PGPPublicKeyRing; -import org.bouncycastle.openpgp.PGPSignature; -import org.pgpainless.algorithm.SignatureType; -import org.pgpainless.signature.SelectSignatureFromKey; - -public class KeyValidator { - - public PGPPublicKeyRing validatePublicKeyRing(PGPPublicKeyRing publicKeys) throws PGPException { - PGPPublicKey primaryKey = publicKeys.getPublicKey(); - if (!isValidPrimaryKey(primaryKey, publicKeys)) { - throw new PGPException("Primary key is not valid"); - } - return publicKeys; - } - - public static boolean isValidPrimaryKey(PGPPublicKey publicKey, PGPPublicKeyRing keyRing) { - if (!publicKey.isMasterKey()) { - return false; - } - - if (keyRing.getPublicKey().getKeyID() != publicKey.getKeyID()) { - return false; - } - - Iterator signatures = publicKey.getSignatures(); - while (signatures.hasNext()) { - PGPSignature signature = signatures.next(); - SignatureType signatureType = SignatureType.valueOf(signature.getSignatureType()); - switch (signatureType) { - case KEY_REVOCATION: - if (SelectSignatureFromKey.isValidKeyRevocationSignature(publicKey).accept(signature, publicKey, keyRing)) { - return false; - } - } - } - return true; - } -} diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/protection/PassphraseMapKeyRingProtector.java b/pgpainless-core/src/main/java/org/pgpainless/key/protection/PassphraseMapKeyRingProtector.java deleted file mode 100644 index fd9b0a4f..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/key/protection/PassphraseMapKeyRingProtector.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 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.protection; - -import java.util.Map; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.pgpainless.key.protection.passphrase_provider.SecretKeyPassphraseProvider; -import org.pgpainless.util.Passphrase; - -/** - * Stub class for API backwards compatibility. - * @deprecated use {@link CachingSecretKeyRingProtector} instead. - */ -@Deprecated -public class PassphraseMapKeyRingProtector extends CachingSecretKeyRingProtector { - - public PassphraseMapKeyRingProtector(@Nonnull Map passphrases, @Nonnull KeyRingProtectionSettings protectionSettings, @Nullable SecretKeyPassphraseProvider missingPassphraseCallback) { - super(passphrases, protectionSettings, missingPassphraseCallback); - } -} diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/SignatureTree.java b/pgpainless-core/src/main/java/org/pgpainless/util/SignatureTree.java deleted file mode 100644 index d1476156..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/util/SignatureTree.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2021 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.util; - -public class SignatureTree { - - public interface Node { - long getKeyId(); - } - - public interface PrimaryKeyNode extends Node { - - } - - public interface SubkeyNode extends Node { - - } - - public interface SignatureNode extends Node { - - } -} diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/Tuple.java b/pgpainless-core/src/main/java/org/pgpainless/util/Tuple.java deleted file mode 100644 index e2eceef7..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/util/Tuple.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2021 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.util; - -public class Tuple { - private final A first; - private final B second; - - public Tuple(A first, B second) { - this.first = first; - this.second = second; - } - - public A getFirst() { - return first; - } - - public B getSecond() { - return second; - } -}