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.sign;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPair;
21 import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPairSpec;
22 import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPairType;
23
24 import java.util.List;
25 import java.util.function.Predicate;
26
27 /**
28 * GordianKnot SignatureFactory API.
29 */
30 public interface GordianSignatureFactory {
31 /**
32 * Create signer.
33 *
34 * @param pSignatureSpec the signatureSpec
35 * @return the signer
36 * @throws GordianException on error
37 */
38 GordianSignature createSigner(GordianSignatureSpec pSignatureSpec) throws GordianException;
39
40 /**
41 * Obtain predicate for signatures.
42 *
43 * @return the predicate
44 */
45 Predicate<GordianSignatureSpec> supportedKeyPairSignatures();
46
47 /**
48 * Obtain a list of supported signatures.
49 *
50 * @param pKeyPairType the keyPairType
51 * @return the list of supported signatureSpecs.
52 */
53 default List<GordianSignatureSpec> listAllSupportedSignatures(final GordianKeyPairType pKeyPairType) {
54 return listPossibleSignatures(pKeyPairType)
55 .stream()
56 .filter(supportedKeyPairSignatures())
57 .toList();
58 }
59
60 /**
61 * Check SignatureSpec and KeyPair combination.
62 *
63 * @param pKeyPair the keyPair
64 * @param pSignSpec the signSpec
65 * @return true/false
66 */
67 default boolean validSignatureSpecForKeyPair(final GordianKeyPair pKeyPair,
68 final GordianSignatureSpec pSignSpec) {
69 return validSignatureSpecForKeyPairSpec(pKeyPair.getKeyPairSpec(), pSignSpec);
70 }
71
72 /**
73 * Check SignatureSpec and KeyPairSpec combination.
74 *
75 * @param pKeyPairSpec the keyPairSpec
76 * @param pSignSpec the signSpec
77 * @return true/false
78 */
79 boolean validSignatureSpecForKeyPairSpec(GordianKeyPairSpec pKeyPairSpec,
80 GordianSignatureSpec pSignSpec);
81
82 /**
83 * Obtain a list of supported signatureSpecs.
84 *
85 * @param pKeyPair the keyPair
86 * @return the list of supported signatureSpecs.
87 */
88 List<GordianSignatureSpec> listAllSupportedSignatures(GordianKeyPair pKeyPair);
89
90 /**
91 * Obtain a list of supported signatureSpecs.
92 *
93 * @param pKeySpec the keySpec
94 * @return the list of supported signatureSpecs.
95 */
96 List<GordianSignatureSpec> listAllSupportedSignatures(GordianKeyPairSpec pKeySpec);
97
98 /**
99 * Obtain a list of all possible signatures for the keyType.
100 *
101 * @param pKeyType the keyType
102 * @return the list
103 */
104 List<GordianSignatureSpec> listPossibleSignatures(GordianKeyPairType pKeyType);
105
106 /**
107 * Create default signatureSpec for keyPair.
108 *
109 * @param pKeySpec the keyPairSpec
110 * @return the SignatureSpec
111 */
112 GordianSignatureSpec defaultForKeyPair(GordianKeyPairSpec pKeySpec);
113 }