diff --git a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java b/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java deleted file mode 100644 index 8fc02e7f..00000000 --- a/pgpainless-core/src/main/java/org/pgpainless/signature/subpackets/SignatureSubpacketGeneratorUtil.java +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Paul Schaub -// -// SPDX-License-Identifier: Apache-2.0 - -package org.pgpainless.signature.subpackets; - -import java.util.Date; -import javax.annotation.Nonnull; - -import org.bouncycastle.bcpg.SignatureSubpacket; -import org.bouncycastle.bcpg.SignatureSubpacketTags; -import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator; - -/** - * Utility class that helps to deal with BCs SignatureSubpacketGenerator class. - */ -public final class SignatureSubpacketGeneratorUtil { - - private SignatureSubpacketGeneratorUtil() { - - } - - /** - * Remove all packets of the given type from the {@link PGPSignatureSubpacketGenerator PGPSignatureSubpacketGenerators} - * internal set. - * - * @param subpacketType type of subpacket to remove - * @param subpacketGenerator subpacket generator - */ - public static void removeAllPacketsOfType(org.pgpainless.algorithm.SignatureSubpacket subpacketType, - PGPSignatureSubpacketGenerator subpacketGenerator) { - removeAllPacketsOfType(subpacketType.getCode(), subpacketGenerator); - } - - /** - * Remove all packets of the given type from the {@link PGPSignatureSubpacketGenerator PGPSignatureSubpacketGenerators} - * internal set. - * - * @param type type of subpacket to remove - * @param subpacketGenerator subpacket generator - */ - public static void removeAllPacketsOfType(int type, PGPSignatureSubpacketGenerator subpacketGenerator) { - for (SignatureSubpacket subpacket : subpacketGenerator.getSubpackets(type)) { - subpacketGenerator.removePacket(subpacket); - } - } - - /** - * Replace all occurrences of a signature creation time subpackets in the subpacket generator - * with a single new instance representing the provided date. - * - * @param date signature creation time - * @param subpacketGenerator subpacket generator - */ - public static void setSignatureCreationTimeInSubpacketGenerator(Date date, PGPSignatureSubpacketGenerator subpacketGenerator) { - removeAllPacketsOfType(SignatureSubpacketTags.CREATION_TIME, subpacketGenerator); - subpacketGenerator.setSignatureCreationTime(false, date); - } - - /** - * Replace all occurrences of key expiration time subpackets in the subpacket generator - * with a single instance representing the new expiration time. - * - * @param expirationDate expiration time as date or null for no expiration - * @param creationDate date on which the key was created - * @param subpacketGenerator subpacket generator - */ - public static void setKeyExpirationDateInSubpacketGenerator(Date expirationDate, - @Nonnull Date creationDate, - PGPSignatureSubpacketGenerator subpacketGenerator) { - removeAllPacketsOfType(SignatureSubpacketTags.KEY_EXPIRE_TIME, subpacketGenerator); - long secondsToExpire = SignatureSubpacketsUtil.getKeyLifetimeInSeconds(expirationDate, creationDate); - subpacketGenerator.setKeyExpirationTime(true, secondsToExpire); - } -} diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/SignatureSubpacketGeneratorUtilTest.java b/pgpainless-core/src/test/java/org/pgpainless/util/SignatureSubpacketGeneratorUtilTest.java deleted file mode 100644 index fe10cf1e..00000000 --- a/pgpainless-core/src/test/java/org/pgpainless/util/SignatureSubpacketGeneratorUtilTest.java +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-FileCopyrightText: 2021 Paul Schaub -// -// SPDX-License-Identifier: Apache-2.0 - -package org.pgpainless.util; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import java.util.Date; - -import org.bouncycastle.bcpg.SignatureSubpacketTags; -import org.bouncycastle.bcpg.sig.Features; -import org.bouncycastle.openpgp.PGPSignatureSubpacketGenerator; -import org.bouncycastle.openpgp.PGPSignatureSubpacketVector; -import org.junit.jupiter.api.Test; -import org.pgpainless.algorithm.SignatureSubpacket; -import org.pgpainless.signature.subpackets.SignatureSubpacketGeneratorUtil; - -public class SignatureSubpacketGeneratorUtilTest { - - @Test - public void testRemoveAllPacketsOfTypeRemovesAll() { - PGPSignatureSubpacketGenerator generator = new PGPSignatureSubpacketGenerator(); - generator.setFeature(false, Features.FEATURE_MODIFICATION_DETECTION); - generator.setSignatureCreationTime(false, new Date()); - generator.setSignatureCreationTime(true, new Date()); - PGPSignatureSubpacketVector vector = generator.generate(); - - assertEquals(2, vector.getSubpackets(SignatureSubpacketTags.CREATION_TIME).length); - assertNotNull(vector.getSubpackets(SignatureSubpacketTags.FEATURES)); - - generator = new PGPSignatureSubpacketGenerator(vector); - SignatureSubpacketGeneratorUtil.removeAllPacketsOfType(SignatureSubpacket.signatureCreationTime, generator); - vector = generator.generate(); - - assertEquals(0, vector.getSubpackets(SignatureSubpacketTags.CREATION_TIME).length); - assertNotNull(vector.getSubpackets(SignatureSubpacketTags.FEATURES)); - } -}