001// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package org.pgpainless.signature.consumer;
006
007import org.bouncycastle.openpgp.PGPOnePassSignature;
008import org.bouncycastle.openpgp.PGPPublicKeyRing;
009import org.bouncycastle.openpgp.PGPSignature;
010import org.pgpainless.key.SubkeyIdentifier;
011
012/**
013 * Tuple-class that bundles together a {@link PGPOnePassSignature} object, a {@link PGPPublicKeyRing}
014 * destined to verify the signature, the {@link PGPSignature} itself and a record of whether the signature
015 * was verified.
016 */
017public class OnePassSignatureCheck {
018    private final PGPOnePassSignature onePassSignature;
019    private final PGPPublicKeyRing verificationKeys;
020    private PGPSignature signature;
021
022    /**
023     * Create a new {@link OnePassSignatureCheck}.
024     *
025     * @param onePassSignature one-pass signature packet used to initialize the signature verifier.
026     * @param verificationKeys verification keys
027     */
028    public OnePassSignatureCheck(PGPOnePassSignature onePassSignature, PGPPublicKeyRing verificationKeys) {
029        this.onePassSignature = onePassSignature;
030        this.verificationKeys = verificationKeys;
031    }
032
033    public void setSignature(PGPSignature signature) {
034        this.signature = signature;
035    }
036
037    /**
038     * Return the {@link PGPOnePassSignature} object.
039     *
040     * @return onePassSignature
041     */
042    public PGPOnePassSignature getOnePassSignature() {
043        return onePassSignature;
044    }
045
046    /**
047     * Return an identifier for the signing key.
048     *
049     * @return signing key fingerprint
050     */
051    public SubkeyIdentifier getSigningKey() {
052        return new SubkeyIdentifier(verificationKeys, onePassSignature.getKeyID());
053    }
054
055    /**
056     * Return the signature.
057     *
058     * @return signature
059     */
060    public PGPSignature getSignature() {
061        return signature;
062    }
063
064    /**
065     * Return the key ring used to verify the signature.
066     *
067     * @return verification keys
068     */
069    public PGPPublicKeyRing getVerificationKeys() {
070        return verificationKeys;
071    }
072}