001/*
002 * Copyright 2018 Paul Schaub.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.pgpainless.encryption_signing;
017
018import javax.annotation.Nonnull;
019import java.io.IOException;
020import java.io.OutputStream;
021
022import org.bouncycastle.openpgp.PGPException;
023import org.bouncycastle.openpgp.PGPPublicKey;
024import org.bouncycastle.openpgp.PGPPublicKeyRing;
025import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
026import org.bouncycastle.openpgp.PGPSecretKey;
027import org.bouncycastle.openpgp.PGPSecretKeyRing;
028import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
029import org.pgpainless.algorithm.CompressionAlgorithm;
030import org.pgpainless.algorithm.HashAlgorithm;
031import org.pgpainless.algorithm.SymmetricKeyAlgorithm;
032import org.pgpainless.exception.SecretKeyNotFoundException;
033import org.pgpainless.key.protection.SecretKeyRingProtector;
034import org.pgpainless.key.selection.keyring.PublicKeyRingSelectionStrategy;
035import org.pgpainless.key.selection.keyring.SecretKeyRingSelectionStrategy;
036import org.pgpainless.util.MultiMap;
037
038public interface EncryptionBuilderInterface {
039
040    ToRecipients onOutputStream(@Nonnull OutputStream outputStream);
041
042    interface ToRecipients {
043
044        WithAlgorithms toRecipients(@Nonnull PGPPublicKey... keys);
045
046        WithAlgorithms toRecipients(@Nonnull PGPPublicKeyRing... keys);
047
048        WithAlgorithms toRecipients(@Nonnull PGPPublicKeyRingCollection... keys);
049
050        <O> WithAlgorithms toRecipients(@Nonnull PublicKeyRingSelectionStrategy<O> selectionStrategy,
051                                       @Nonnull MultiMap<O, PGPPublicKeyRingCollection> keys);
052
053        SignWith doNotEncrypt();
054
055    }
056
057    interface WithAlgorithms {
058
059        WithAlgorithms andToSelf(@Nonnull PGPPublicKey... keys);
060
061        WithAlgorithms andToSelf(@Nonnull PGPPublicKeyRing... keys);
062
063        WithAlgorithms andToSelf(@Nonnull PGPPublicKeyRingCollection keys);
064
065        <O> WithAlgorithms andToSelf(@Nonnull PublicKeyRingSelectionStrategy<O> selectionStrategy,
066                                    @Nonnull MultiMap<O, PGPPublicKeyRingCollection> keys);
067
068        SignWith usingAlgorithms(@Nonnull SymmetricKeyAlgorithm symmetricKeyAlgorithm,
069                                 @Nonnull HashAlgorithm hashAlgorithm,
070                                 @Nonnull CompressionAlgorithm compressionAlgorithm);
071
072        SignWith usingSecureAlgorithms();
073
074    }
075
076    interface SignWith {
077
078        <O> Armor signWith(@Nonnull SecretKeyRingProtector decryptor, @Nonnull PGPSecretKey... keys);
079
080        <O> Armor signWith(@Nonnull SecretKeyRingProtector decryptor, @Nonnull PGPSecretKeyRing... keyRings);
081
082        <O> Armor signWith(@Nonnull SecretKeyRingSelectionStrategy<O> selectionStrategy,
083                          @Nonnull SecretKeyRingProtector decryptor,
084                          @Nonnull MultiMap<O, PGPSecretKeyRingCollection> keys)
085                throws SecretKeyNotFoundException;
086
087        Armor doNotSign();
088
089    }
090
091    interface Armor {
092
093        EncryptionStream asciiArmor() throws IOException, PGPException;
094
095        EncryptionStream noArmor() throws IOException, PGPException;
096
097    }
098
099}