001/**
002 *
003 * Copyright 2018 Paul Schaub.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.ox.exception;
018
019import org.jxmpp.jid.BareJid;
020import org.pgpainless.key.OpenPgpV4Fingerprint;
021
022/**
023 * Exception that gets thrown when an operation is missing an OpenPGP key.
024 */
025public class MissingOpenPgpKeyException extends Exception {
026
027    private static final long serialVersionUID = 1L;
028
029    private final BareJid owner;
030    private final OpenPgpV4Fingerprint fingerprint;
031
032    /**
033     * Create a new {@link MissingOpenPgpKeyException}.
034     *
035     * @param owner {@link BareJid} of the keys owner.
036     * @param fingerprint {@link OpenPgpV4Fingerprint} of the missing key.
037     */
038    public MissingOpenPgpKeyException(BareJid owner, OpenPgpV4Fingerprint fingerprint) {
039        super("Missing key " + fingerprint.toString() + " for owner " + owner + ".");
040        this.owner = owner;
041        this.fingerprint = fingerprint;
042    }
043
044    public MissingOpenPgpKeyException(BareJid owner, OpenPgpV4Fingerprint fingerprint, Throwable e) {
045        super("Missing key " + fingerprint.toString() + " for owner " + owner + ".", e);
046        this.owner = owner;
047        this.fingerprint = fingerprint;
048    }
049
050
051    /**
052     * Return the {@link BareJid} of the owner of the missing key.
053     *
054     * @return owner of missing key.
055     */
056    public BareJid getOwner() {
057        return owner;
058    }
059
060    /**
061     * Return the {@link OpenPgpV4Fingerprint} of the missing key.
062     *
063     * @return {@link OpenPgpV4Fingerprint} of the missing key.
064     */
065    public OpenPgpV4Fingerprint getFingerprint() {
066        return fingerprint;
067    }
068}