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.keypair;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairSpec;
21 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairSpecBuilder;
22 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairType;
23
24 import java.security.spec.PKCS8EncodedKeySpec;
25 import java.security.spec.X509EncodedKeySpec;
26 import java.util.List;
27 import java.util.function.Predicate;
28
29 /**
30 * KeyPair Factory API.
31 */
32 public interface GordianKeyPairFactory {
33 /**
34 * Obtain keyPair generator.
35 *
36 * @param pKeySpec the keySpec
37 * @return the generator
38 * @throws GordianException on error
39 */
40 GordianKeyPairGenerator getKeyPairGenerator(GordianKeyPairSpec pKeySpec) throws GordianException;
41
42 /**
43 * create new GordianKeyPairSpecBuilder.
44 *
45 * @return the new KeyPairSpecBuilder
46 */
47 GordianKeyPairSpecBuilder newKeyPairSpecBuilder();
48
49 /**
50 * Determine KeySpec from PKCS8EncodedKeySpec.
51 *
52 * @param pEncoded the encodedKeySpec
53 * @return the keySpec
54 * @throws GordianException on error
55 */
56 GordianKeyPairSpec determineKeyPairSpec(PKCS8EncodedKeySpec pEncoded) throws GordianException;
57
58 /**
59 * Determine KeySpec from X509EncodedKeySpec.
60 *
61 * @param pEncoded the encodedKeySpec
62 * @return the keySpec
63 * @throws GordianException on error
64 */
65 GordianKeyPairSpec determineKeyPairSpec(X509EncodedKeySpec pEncoded) throws GordianException;
66
67 /**
68 * Obtain predicate for keyPairSpecs.
69 *
70 * @return the predicate
71 */
72 Predicate<GordianKeyPairSpec> supportedKeyPairSpecs();
73
74 /**
75 * Obtain a list of supported keyPairSpecs.
76 *
77 * @return the list of supported keyPairSpecs.
78 */
79 List<GordianKeyPairSpec> listAllSupportedKeyPairSpecs();
80
81 /**
82 * Obtain a list of supported KeyPairSpecs for a KeyPairType.
83 *
84 * @param pKeyPairType the keyPairType
85 * @return the list of supported asymKeySpecs.
86 */
87 List<GordianKeyPairSpec> listAllSupportedKeyPairSpecs(GordianKeyPairType pKeyPairType);
88
89 /**
90 * Obtain a list of all possible keyPairSpecs.
91 *
92 * @return the list
93 */
94 List<GordianKeyPairSpec> listPossibleKeySpecs();
95 }