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.PGPKeyRing;
008import org.bouncycastle.openpgp.PGPSignature;
009import org.pgpainless.key.OpenPgpFingerprint;
010import org.pgpainless.key.SubkeyIdentifier;
011
012/**
013 * Tuple-class which bundles together a signature, the signing key that created the signature,
014 * an identifier of the signing key and a record of whether the signature was verified.
015 */
016public class DetachedSignatureCheck {
017    private final PGPSignature signature;
018    private final PGPKeyRing signingKeyRing;
019    private final SubkeyIdentifier signingKeyIdentifier;
020
021    /**
022     * Create a new {@link DetachedSignatureCheck} object.
023     *
024     * @param signature signature
025     * @param signingKeyRing signing key that created the signature
026     * @param signingKeyIdentifier identifier of the used signing key
027     */
028    public DetachedSignatureCheck(PGPSignature signature, PGPKeyRing signingKeyRing, SubkeyIdentifier signingKeyIdentifier) {
029        this.signature = signature;
030        this.signingKeyRing = signingKeyRing;
031        this.signingKeyIdentifier = signingKeyIdentifier;
032    }
033
034    /**
035     * Return the OpenPGP signature.
036     *
037     * @return signature
038     */
039    public PGPSignature getSignature() {
040        return signature;
041    }
042
043    /**
044     * Return an identifier pointing to the exact signing key which was used to create this signature.
045     *
046     * @return signing key identifier
047     */
048    public SubkeyIdentifier getSigningKeyIdentifier() {
049        return signingKeyIdentifier;
050    }
051
052    /**
053     * Return the key ring that contains the signing key that created this signature.
054     *
055     * @return key ring
056     */
057    public PGPKeyRing getSigningKeyRing() {
058        return signingKeyRing;
059    }
060
061    /**
062     * Return the {@link OpenPgpFingerprint} of the key that created the signature.
063     *
064     * @return fingerprint of the signing key
065     * @deprecated use {@link #getSigningKeyIdentifier()} instead.
066     */
067    @Deprecated
068    public OpenPgpFingerprint getFingerprint() {
069        return signingKeyIdentifier.getSubkeyFingerprint();
070    }
071}