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