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.cipher;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianKeySpec;
21 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianLength;
22 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianPBESpecBuilder;
23 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamCipherSpec;
24 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamCipherSpecBuilder;
25 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySpec;
26 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeySpecBuilder;
27 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianStreamKeyType;
28 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymCipherSpec;
29 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymCipherSpecBuilder;
30 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpec;
31 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeySpecBuilder;
32 import io.github.tonywasher.joceanus.gordianknot.api.cipher.spec.GordianSymKeyType;
33 import io.github.tonywasher.joceanus.gordianknot.api.key.GordianKey;
34 import io.github.tonywasher.joceanus.gordianknot.api.key.GordianKeyGenerator;
35
36 import java.util.List;
37 import java.util.function.Predicate;
38
39 /**
40 * Cipher factory.
41 */
42 public interface GordianCipherFactory {
43 /**
44 * obtain GordianKeyGenerator for SymKeySpec.
45 *
46 * @param <T> the key type
47 * @param pKeyType the KeyType
48 * @return the new KeyGenerator
49 * @throws GordianException on error
50 */
51 <T extends GordianKeySpec> GordianKeyGenerator<T> getKeyGenerator(T pKeyType) throws GordianException;
52
53 /**
54 * create GordianSymCipher.
55 *
56 * @param pCipherSpec the cipherSpec
57 * @return the new Cipher
58 * @throws GordianException on error
59 */
60 GordianSymCipher createSymKeyCipher(GordianSymCipherSpec pCipherSpec) throws GordianException;
61
62 /**
63 * create GordianStreamCipher.
64 *
65 * @param pCipherSpec the cipherSpec
66 * @return the new Cipher
67 * @throws GordianException on error
68 */
69 GordianStreamCipher createStreamKeyCipher(GordianStreamCipherSpec pCipherSpec) throws GordianException;
70
71 /**
72 * create new GordianSymKeySpecBuilder.
73 *
74 * @return the new SymKeySpecBuilder
75 */
76 GordianSymKeySpecBuilder newSymKeySpecBuilder();
77
78 /**
79 * create new GordianStreamKeySpecBuilder.
80 *
81 * @return the new StreamKeySpecBuilder
82 */
83 GordianStreamKeySpecBuilder newStreamKeySpecBuilder();
84
85 /**
86 * create new GordianSymCipherSpecBuilder.
87 *
88 * @return the new SymCipherSpecBuilder
89 */
90 GordianSymCipherSpecBuilder newSymCipherSpecBuilder();
91
92 /**
93 * create new GordianStreamCipherSpecBuilder.
94 *
95 * @return the new StreamCipherSpecBuilder
96 */
97 GordianStreamCipherSpecBuilder newStreamCipherSpecBuilder();
98
99 /**
100 * create new GordianCipherParamsBuilder.
101 *
102 * @return the new CipherParamsBuilder
103 */
104 GordianCipherParamsBuilder newCipherParamsBuilder();
105
106 /**
107 * create new GordianPBESpecBuilder.
108 *
109 * @return the new PBESpecBuilder
110 */
111 GordianPBESpecBuilder newPBESpecBuilder();
112
113 /**
114 * Obtain predicate for supported symKeySpecs.
115 *
116 * @return the predicate
117 */
118 Predicate<GordianSymKeySpec> supportedSymKeySpecs();
119
120 /**
121 * Obtain predicate for supported symCipherSpecs.
122 *
123 * @return the predicate
124 */
125 Predicate<GordianSymCipherSpec> supportedSymCipherSpecs();
126
127 /**
128 * Obtain predicate for supported SymKeyTypes.
129 *
130 * @return the predicate
131 */
132 Predicate<GordianSymKeyType> supportedSymKeyTypes();
133
134 /**
135 * Obtain predicate for supported streamKeySpecs.
136 *
137 * @return the predicate
138 */
139 Predicate<GordianStreamKeySpec> supportedStreamKeySpecs();
140
141 /**
142 * Obtain predicate for supported streamCipherSpecs.
143 *
144 * @return the predicate
145 */
146 Predicate<GordianStreamCipherSpec> supportedStreamCipherSpecs();
147
148 /**
149 * Obtain predicate for supported StreamKeyTypes.
150 *
151 * @return the predicate
152 */
153 Predicate<GordianStreamKeyType> supportedStreamKeyTypes();
154
155 /**
156 * create GordianWrapper.
157 *
158 * @param pKey the Key
159 * @return the new wrapper
160 * @throws GordianException on error
161 */
162 GordianWrapper createKeyWrapper(GordianKey<GordianSymKeySpec> pKey) throws GordianException;
163
164 /**
165 * Obtain a list of supported symCipherSpecs.
166 *
167 * @param pSpec the symKeySpec
168 * @return the list of supported symCipherSpecs.
169 */
170 List<GordianSymCipherSpec> listAllSupportedSymCipherSpecs(GordianSymKeySpec pSpec);
171
172 /**
173 * Obtain a list of supported symKeySpecs for the keyLength.
174 *
175 * @param pKeyLen the keyLength
176 * @return the list of supported symKeySpecs.
177 */
178 List<GordianSymKeySpec> listAllSupportedSymKeySpecs(GordianLength pKeyLen);
179
180 /**
181 * List all possible symKeySpecs for the keyLength.
182 *
183 * @param pKeyLen the keyLength
184 * @return the list
185 */
186 List<GordianSymKeySpec> listAllSymKeySpecs(GordianLength pKeyLen);
187
188 /**
189 * Obtain a list of supported symKeyTypes.
190 *
191 * @return the list of supported symKeyTypes.
192 */
193 List<GordianSymKeyType> listAllSupportedSymKeyTypes();
194
195 /**
196 * Obtain a list of supported streamCipherSpecs for the keyLength.
197 *
198 * @param pKeyLen the keyLength
199 * @return the list of supported streamCipherSpecs.
200 */
201 List<GordianStreamCipherSpec> listAllSupportedStreamCipherSpecs(GordianLength pKeyLen);
202
203 /**
204 * Obtain a list of supported streamKeySpecs for the keyLength.
205 *
206 * @param pKeyLen the keyLength
207 * @return the list of supported streamKeySpecs.
208 */
209 List<GordianStreamKeySpec> listAllSupportedStreamKeySpecs(GordianLength pKeyLen);
210
211 /**
212 * Obtain a list of supported streamKeyTypes.
213 *
214 * @return the list of supported streamKeyTypes.
215 */
216 List<GordianStreamKeyType> listAllSupportedStreamKeyTypes();
217
218 /**
219 * List all possible cipherSpecs for a SymKeySpec.
220 *
221 * @param pSpec the keySpec
222 * @return the list
223 */
224 List<GordianSymCipherSpec> listAllSymCipherSpecs(GordianSymKeySpec pSpec);
225 }