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