pgpainless/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilderInterface.java

75 lines
2.4 KiB
Java
Raw Normal View History

/*
2020-10-20 22:58:45 +02:00
* Copyright 2018-2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key.generation;
2018-06-02 21:21:35 +02:00
import java.security.InvalidAlgorithmParameterException;
2018-06-02 21:21:35 +02:00
import java.security.NoSuchAlgorithmException;
import java.util.Date;
2020-12-08 19:14:52 +01:00
import javax.annotation.Nonnull;
2018-06-02 21:21:35 +02:00
import org.bouncycastle.openpgp.PGPException;
2020-12-08 19:14:52 +01:00
import org.bouncycastle.openpgp.PGPSecretKeyRing;
2020-11-13 15:59:28 +01:00
import org.pgpainless.key.util.UserId;
import org.pgpainless.util.Passphrase;
2018-06-02 21:21:35 +02:00
public interface KeyRingBuilderInterface {
KeyRingBuilderInterface withSubKey(@Nonnull KeySpec keySpec);
2018-06-02 21:21:35 +02:00
WithPrimaryUserId withPrimaryKey(@Nonnull KeySpec keySpec);
2018-06-02 21:21:35 +02:00
interface WithPrimaryUserId {
2020-11-13 15:59:28 +01:00
default WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull UserId userId) {
return withPrimaryUserId(userId.toString());
}
WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull String userId);
2018-06-02 21:21:35 +02:00
WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull byte[] userId);
2018-06-02 21:21:35 +02:00
}
interface WithAdditionalUserIdOrPassphrase {
2020-11-13 15:59:28 +01:00
default WithAdditionalUserIdOrPassphrase withAdditionalUserId(@Nonnull UserId userId) {
return withAdditionalUserId(userId.toString());
}
/**
* Set an expiration date for the key.
*
* @param expirationDate date on which the key will expire.
* @return builder
*/
WithAdditionalUserIdOrPassphrase setExpirationDate(@Nonnull Date expirationDate);
WithAdditionalUserIdOrPassphrase withAdditionalUserId(@Nonnull String userId);
WithAdditionalUserIdOrPassphrase withAdditionalUserId(@Nonnull byte[] userId);
2018-06-02 21:21:35 +02:00
Build withPassphrase(@Nonnull Passphrase passphrase);
2018-06-02 21:21:35 +02:00
Build withoutPassphrase();
}
interface Build {
2020-12-08 19:14:52 +01:00
PGPSecretKeyRing build() throws NoSuchAlgorithmException, PGPException,
InvalidAlgorithmParameterException;
2018-06-02 21:21:35 +02:00
}
}