1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-17 18:02:05 +01:00

Remove unused SignatureSubpacketGeneratorUtil class and tests

This commit is contained in:
Paul Schaub 2022-08-29 11:30:26 +02:00
parent 0cc884523c
commit 1b04d67e1a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 0 additions and 115 deletions

View file

@ -1,75 +0,0 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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);
}
}

View file

@ -1,40 +0,0 @@
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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));
}
}