001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package org.pgpainless.signature.builder;
006
007import javax.annotation.Nullable;
008
009import org.bouncycastle.openpgp.PGPException;
010import org.bouncycastle.openpgp.PGPSecretKey;
011import org.bouncycastle.openpgp.PGPSignature;
012import org.bouncycastle.openpgp.PGPSignatureGenerator;
013import org.pgpainless.algorithm.SignatureType;
014import org.pgpainless.key.protection.SecretKeyRingProtector;
015import org.pgpainless.signature.subpackets.BaseSignatureSubpackets;
016import org.pgpainless.signature.subpackets.SignatureSubpackets;
017
018/**
019 * Signature builder without restrictions on subpacket contents.
020 */
021public class UniversalSignatureBuilder extends AbstractSignatureBuilder<UniversalSignatureBuilder> {
022
023    public UniversalSignatureBuilder(SignatureType signatureType, PGPSecretKey signingKey, SecretKeyRingProtector protector)
024            throws PGPException {
025        super(signatureType, signingKey, protector);
026    }
027
028    public UniversalSignatureBuilder(PGPSecretKey certificationKey, SecretKeyRingProtector protector, PGPSignature archetypeSignature)
029            throws PGPException {
030        super(certificationKey, protector, archetypeSignature);
031    }
032
033    @Override
034    protected boolean isValidSignatureType(SignatureType type) {
035        return true;
036    }
037
038    public SignatureSubpackets getHashedSubpackets() {
039        return hashedSubpackets;
040    }
041
042    public SignatureSubpackets getUnhashedSubpackets() {
043        return unhashedSubpackets;
044    }
045
046    public void applyCallback(@Nullable BaseSignatureSubpackets.Callback callback) {
047        if (callback != null) {
048            callback.modifyHashedSubpackets(getHashedSubpackets());
049            callback.modifyUnhashedSubpackets(getUnhashedSubpackets());
050        }
051    }
052
053    public PGPSignatureGenerator getSignatureGenerator() throws PGPException {
054        return buildAndInitSignatureGenerator();
055    }
056}