001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package sop.operation;
006
007import java.io.ByteArrayInputStream;
008import java.io.IOException;
009import java.io.InputStream;
010
011import sop.Ready;
012import sop.enums.SignAs;
013import sop.exception.SOPGPException;
014
015public interface Sign {
016
017    /**
018     * Disable ASCII armor encoding.
019     *
020     * @return builder instance
021     */
022    Sign noArmor();
023
024    /**
025     * Sets the signature mode.
026     * Note: This method has to be called before {@link #key(InputStream)} is called.
027     *
028     * @param mode signature mode
029     * @return builder instance
030     */
031    Sign mode(SignAs mode) throws SOPGPException.UnsupportedOption;
032
033    /**
034     * Adds the signer key.
035     *
036     * @param key input stream containing encoded key
037     * @return builder instance
038     */
039    Sign key(InputStream key) throws SOPGPException.KeyIsProtected, SOPGPException.BadData, IOException;
040
041    /**
042     * Adds the signer key.
043     *
044     * @param key byte array containing encoded key
045     * @return builder instance
046     */
047    default Sign key(byte[] key) throws SOPGPException.KeyIsProtected, SOPGPException.BadData, IOException {
048        return key(new ByteArrayInputStream(key));
049    }
050
051    /**
052     * Signs data.
053     *
054     * @param data input stream containing data
055     * @return ready
056     */
057    Ready data(InputStream data) throws IOException, SOPGPException.ExpectedText;
058
059    /**
060     * Signs data.
061     *
062     * @param data byte array containing data
063     * @return ready
064     */
065    default Ready data(byte[] data) throws IOException, SOPGPException.ExpectedText {
066        return data(new ByteArrayInputStream(data));
067    }
068}