1 /*
2 * GordianKnot: Security Suite
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.gordianknot.api.encrypt;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.encrypt.spec.GordianEncryptorSpec;
21 import io.github.tonywasher.joceanus.gordianknot.api.encrypt.spec.GordianEncryptorSpecBuilder;
22 import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPair;
23 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairSpec;
24 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairType;
25
26 import java.util.List;
27 import java.util.function.Predicate;
28
29 /**
30 * GordianKnot EncryptorFactory API.
31 */
32 public interface GordianEncryptorFactory {
33 /**
34 * Create keyPairEncryptor.
35 *
36 * @param pSpec the encryptorSpec
37 * @return the Encryptor
38 * @throws GordianException on error
39 */
40 GordianEncryptor createEncryptor(GordianEncryptorSpec pSpec) throws GordianException;
41
42 /**
43 * create new GordianEncryptorSpecBuilder.
44 *
45 * @return the new EncryptorSpecBuilder
46 */
47 GordianEncryptorSpecBuilder newEncryptorSpecBuilder();
48
49 /**
50 * Obtain predicate for Encryptor.
51 *
52 * @return the predicate
53 */
54 Predicate<GordianEncryptorSpec> supportedEncryptors();
55
56 /**
57 * Obtain a list of supported encryptorSpecs.
58 *
59 * @param pKeyType the keyType
60 * @return the list of supported encryptorSpecs.
61 */
62 default List<GordianEncryptorSpec> listAllSupportedEncryptors(final GordianKeyPairType pKeyType) {
63 return listPossibleEncryptors(pKeyType)
64 .stream()
65 .filter(supportedEncryptors())
66 .toList();
67 }
68
69 /**
70 * Check EncryptorSpec and KeyPair combination.
71 *
72 * @param pKeyPair the keyPair
73 * @param pEncryptorSpec the macSpec
74 * @return true/false
75 */
76 default boolean validEncryptorSpecForKeyPair(final GordianKeyPair pKeyPair,
77 final GordianEncryptorSpec pEncryptorSpec) {
78 return validEncryptorSpecForKeyPairSpec(pKeyPair.getKeyPairSpec(), pEncryptorSpec);
79 }
80
81 /**
82 * Check EncryptorSpec and KeyPairSpec combination.
83 *
84 * @param pKeyPairSpec the keyPairSpec
85 * @param pEncryptorSpec the macSpec
86 * @return true/false
87 */
88 boolean validEncryptorSpecForKeyPairSpec(GordianKeyPairSpec pKeyPairSpec,
89 GordianEncryptorSpec pEncryptorSpec);
90
91 /**
92 * Obtain a list of supported encryptorSpecs.
93 *
94 * @param pKeyPair the keyPair
95 * @return the list of supported encryptorSpecs.
96 */
97 List<GordianEncryptorSpec> listAllSupportedEncryptors(GordianKeyPair pKeyPair);
98
99 /**
100 * Obtain a list of supported encryptorSpecs.
101 *
102 * @param pKeyPairSpec the keySpec
103 * @return the list of supported encryptorSpecs.
104 */
105 List<GordianEncryptorSpec> listAllSupportedEncryptors(GordianKeyPairSpec pKeyPairSpec);
106
107 /**
108 * Obtain a list of all possible encryptors for the keyType.
109 *
110 * @param pKeyPairType the keyPairType
111 * @return the list
112 */
113 List<GordianEncryptorSpec> listPossibleEncryptors(GordianKeyPairType pKeyPairType);
114
115 /**
116 * Create default signatureSpec for key.
117 *
118 * @param pKeySpec the keySpec
119 * @return the SignatureSpec
120 */
121 GordianEncryptorSpec defaultForKeyPair(GordianKeyPairSpec pKeySpec);
122 }