mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-23 04:42:06 +01:00
Rename CertificationSignatureBuilder to ThirdPartyCertificationSignatureBuilder
Also add javadoc
This commit is contained in:
parent
936ea55cee
commit
c229562573
2 changed files with 118 additions and 76 deletions
|
@ -1,76 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.signature.builder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.exception.WrongPassphraseException;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.signature.subpackets.CertificationSubpackets;
|
||||
|
||||
public class CertificationSignatureBuilder extends AbstractSignatureBuilder<CertificationSignatureBuilder> {
|
||||
|
||||
public CertificationSignatureBuilder(PGPSecretKey certificationKey, SecretKeyRingProtector protector)
|
||||
throws WrongPassphraseException {
|
||||
this(SignatureType.GENERIC_CERTIFICATION, certificationKey, protector);
|
||||
}
|
||||
|
||||
public CertificationSignatureBuilder(SignatureType signatureType, PGPSecretKey signingKey, SecretKeyRingProtector protector)
|
||||
throws WrongPassphraseException {
|
||||
super(signatureType, signingKey, protector);
|
||||
}
|
||||
|
||||
public CertificationSignatureBuilder(
|
||||
PGPSecretKey certificationKey,
|
||||
SecretKeyRingProtector protector,
|
||||
PGPSignature archetypeSignature)
|
||||
throws WrongPassphraseException {
|
||||
super(certificationKey, protector, archetypeSignature);
|
||||
}
|
||||
|
||||
public CertificationSubpackets getHashedSubpackets() {
|
||||
return hashedSubpackets;
|
||||
}
|
||||
|
||||
public CertificationSubpackets getUnhashedSubpackets() {
|
||||
return unhashedSubpackets;
|
||||
}
|
||||
|
||||
public void applyCallback(@Nullable CertificationSubpackets.Callback callback) {
|
||||
if (callback != null) {
|
||||
callback.modifyHashedSubpackets(getHashedSubpackets());
|
||||
callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
|
||||
}
|
||||
}
|
||||
|
||||
public PGPSignature build(PGPPublicKey certifiedKey, String userId) throws PGPException {
|
||||
return buildAndInitSignatureGenerator().generateCertification(userId, certifiedKey);
|
||||
}
|
||||
|
||||
public PGPSignature build(PGPPublicKey certifiedKey, PGPUserAttributeSubpacketVector userAttribute)
|
||||
throws PGPException {
|
||||
return buildAndInitSignatureGenerator().generateCertification(userAttribute, certifiedKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidSignatureType(@Nonnull SignatureType type) {
|
||||
switch (type) {
|
||||
case GENERIC_CERTIFICATION:
|
||||
case NO_CERTIFICATION:
|
||||
case CASUAL_CERTIFICATION:
|
||||
case POSITIVE_CERTIFICATION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.signature.builder;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPPublicKey;
|
||||
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKey;
|
||||
import org.bouncycastle.openpgp.PGPSignature;
|
||||
import org.bouncycastle.openpgp.PGPUserAttributeSubpacketVector;
|
||||
import org.pgpainless.algorithm.SignatureType;
|
||||
import org.pgpainless.exception.WrongPassphraseException;
|
||||
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||||
import org.pgpainless.signature.subpackets.CertificationSubpackets;
|
||||
|
||||
/**
|
||||
* Certification signature builder used to certify other users keys.
|
||||
*/
|
||||
public class ThirdPartyCertificationSignatureBuilder extends AbstractSignatureBuilder<ThirdPartyCertificationSignatureBuilder> {
|
||||
|
||||
/**
|
||||
* Create a new certification signature builder.
|
||||
* This constructor uses {@link SignatureType#GENERIC_CERTIFICATION} as signature type.
|
||||
*
|
||||
* @param signingKey our own certification key
|
||||
* @param protector protector to unlock the certification key
|
||||
* @throws WrongPassphraseException in case of a wrong passphrase
|
||||
*/
|
||||
public ThirdPartyCertificationSignatureBuilder(PGPSecretKey signingKey, SecretKeyRingProtector protector)
|
||||
throws WrongPassphraseException {
|
||||
this(SignatureType.GENERIC_CERTIFICATION, signingKey, protector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new certification signature builder.
|
||||
*
|
||||
* @param signatureType type of certification
|
||||
* @param signingKey our own certification key
|
||||
* @param protector protector to unlock the certification key
|
||||
* @throws WrongPassphraseException in case of a wrong passphrase
|
||||
*/
|
||||
public ThirdPartyCertificationSignatureBuilder(SignatureType signatureType, PGPSecretKey signingKey, SecretKeyRingProtector protector)
|
||||
throws WrongPassphraseException {
|
||||
super(signatureType, signingKey, protector);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new certification signature builder.
|
||||
*
|
||||
* @param signingKey our own certification key
|
||||
* @param protector protector to unlock the certification key
|
||||
* @param archetypeSignature signature to use as a template for the new signature
|
||||
* @throws WrongPassphraseException in case of a wrong passphrase
|
||||
*/
|
||||
public ThirdPartyCertificationSignatureBuilder(
|
||||
PGPSecretKey signingKey,
|
||||
SecretKeyRingProtector protector,
|
||||
PGPSignature archetypeSignature)
|
||||
throws WrongPassphraseException {
|
||||
super(signingKey, protector, archetypeSignature);
|
||||
}
|
||||
|
||||
public CertificationSubpackets getHashedSubpackets() {
|
||||
return hashedSubpackets;
|
||||
}
|
||||
|
||||
public CertificationSubpackets getUnhashedSubpackets() {
|
||||
return unhashedSubpackets;
|
||||
}
|
||||
|
||||
public void applyCallback(@Nullable CertificationSubpackets.Callback callback) {
|
||||
if (callback != null) {
|
||||
callback.modifyHashedSubpackets(getHashedSubpackets());
|
||||
callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a certification signature for the given user-id and the primary key of the given key ring.
|
||||
* @param certifiedKey key ring
|
||||
* @param userId user-id to certify
|
||||
* @return signature
|
||||
* @throws PGPException
|
||||
*/
|
||||
public PGPSignature build(PGPPublicKeyRing certifiedKey, String userId) throws PGPException {
|
||||
return buildAndInitSignatureGenerator().generateCertification(userId, certifiedKey.getPublicKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a certification signature for the given user attribute and the primary key of the given key ring.
|
||||
* @param certifiedKey key ring
|
||||
* @param userAttribute user-attributes to certify
|
||||
* @return signature
|
||||
* @throws PGPException
|
||||
*/
|
||||
public PGPSignature build(PGPPublicKeyRing certifiedKey, PGPUserAttributeSubpacketVector userAttribute)
|
||||
throws PGPException {
|
||||
return buildAndInitSignatureGenerator().generateCertification(userAttribute, certifiedKey.getPublicKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isValidSignatureType(@Nonnull SignatureType type) {
|
||||
switch (type) {
|
||||
case GENERIC_CERTIFICATION:
|
||||
case NO_CERTIFICATION:
|
||||
case CASUAL_CERTIFICATION:
|
||||
case POSITIVE_CERTIFICATION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue