View Javadoc
1   /*
2    * GordianKnot: Security Suite
3    * Copyright 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  
18  package io.github.tonywasher.joceanus.gordianknot.api.sign.spec;
19  
20  import io.github.tonywasher.joceanus.gordianknot.api.base.GordianLength;
21  import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
22  import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpecBuilder;
23  import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairType;
24  
25  import java.util.Arrays;
26  import java.util.List;
27  
28  /**
29   * Signature Specification Builder.
30   */
31  public interface GordianSignatureSpecBuilder {
32      /**
33       * Define keyPairType.
34       *
35       * @param pType the type
36       * @return the Builder
37       */
38      GordianSignatureSpecBuilder withKeyPairType(GordianKeyPairType pType);
39  
40      /**
41       * Define signatureType.
42       *
43       * @param pSignatureType the signatureType
44       * @return the Builder
45       */
46      GordianSignatureSpecBuilder withSignatureType(GordianSignatureType pSignatureType);
47  
48      /**
49       * Define digestSpec.
50       *
51       * @param pDigestSpec the digest spec
52       * @return the Builder
53       */
54      GordianSignatureSpecBuilder withDigestSpec(GordianDigestSpec pDigestSpec);
55  
56      /**
57       * Define signatureSpec list.
58       *
59       * @param pSpecs the specs
60       * @return the builder
61       */
62      GordianSignatureSpecBuilder withSignatureSpecs(List<GordianSignatureSpec> pSpecs);
63  
64      /**
65       * Access digestSpecBuilder.
66       *
67       * @return the digestSpec builder
68       */
69      GordianDigestSpecBuilder usingDigestSpecBuilder();
70  
71      /**
72       * Build signatureSpec.
73       *
74       * @return the signatureSpec
75       */
76      GordianSignatureSpec build();
77  
78      /**
79       * Create RSASpec.
80       *
81       * @param pSignatureType the signatureType
82       * @param pDigestSpec    the digestSpec
83       * @return the SignatureSpec
84       */
85      default GordianSignatureSpec rsa(final GordianSignatureType pSignatureType,
86                                       final GordianDigestSpec pDigestSpec) {
87          return withKeyPairType(GordianKeyPairType.RSA).withSignatureType(pSignatureType).withDigestSpec(pDigestSpec).build();
88      }
89  
90      /**
91       * Create DSASpec.
92       *
93       * @param pSignatureType the signatureType
94       * @param pDigestSpec    the digestSpec
95       * @return the SignatureSpec
96       */
97      default GordianSignatureSpec dsa(final GordianSignatureType pSignatureType,
98                                       final GordianDigestSpec pDigestSpec) {
99          return withKeyPairType(GordianKeyPairType.DSA).withSignatureType(pSignatureType).withDigestSpec(pDigestSpec).build();
100     }
101 
102     /**
103      * Create ECSpec.
104      *
105      * @param pSignatureType the signatureType
106      * @param pDigestSpec    the digestSpec
107      * @return the SignatureSpec
108      */
109     default GordianSignatureSpec ec(final GordianSignatureType pSignatureType,
110                                     final GordianDigestSpec pDigestSpec) {
111         return withKeyPairType(GordianKeyPairType.EC).withSignatureType(pSignatureType).withDigestSpec(pDigestSpec).build();
112     }
113 
114     /**
115      * Create SM2Spec.
116      *
117      * @param pDigestSpec the digestSpec
118      * @return the SignatureSpec
119      */
120     default GordianSignatureSpec sm2(final GordianDigestSpec pDigestSpec) {
121         return withKeyPairType(GordianKeyPairType.SM2).withDigestSpec(pDigestSpec).build();
122     }
123 
124     /**
125      * Create DSTU4145Spec.
126      *
127      * @return the SignatureSpec
128      */
129     default GordianSignatureSpec dstu4145() {
130         return withKeyPairType(GordianKeyPairType.DSTU).withDigestSpec(usingDigestSpecBuilder().gost()).build();
131     }
132 
133     /**
134      * Create GOST2012Spec.
135      *
136      * @param pLength the length
137      * @return the SignatureSpec
138      */
139     default GordianSignatureSpec gost2012(final GordianLength pLength) {
140         return withKeyPairType(GordianKeyPairType.GOST).withDigestSpec(usingDigestSpecBuilder().streebog(pLength)).build();
141     }
142 
143     /**
144      * Create EdDSASpec.
145      *
146      * @return the SignatureSpec
147      */
148     default GordianSignatureSpec edDSA() {
149         return withKeyPairType(GordianKeyPairType.EDDSA).build();
150     }
151 
152     /**
153      * Create SLHDSASpec.
154      *
155      * @return the SignatureSpec
156      */
157     default GordianSignatureSpec slhdsa() {
158         return withKeyPairType(GordianKeyPairType.SLHDSA).build();
159     }
160 
161     /**
162      * Create MLDSASpec.
163      *
164      * @return the SignatureSpec
165      */
166     default GordianSignatureSpec mldsa() {
167         return withKeyPairType(GordianKeyPairType.MLDSA).build();
168     }
169 
170     /**
171      * Create falconSpec.
172      *
173      * @return the SignatureSpec
174      */
175     default GordianSignatureSpec falcon() {
176         return withKeyPairType(GordianKeyPairType.FALCON).build();
177     }
178 
179     /**
180      * Create mayoSpec.
181      *
182      * @return the SignatureSpec
183      */
184     default GordianSignatureSpec mayo() {
185         return withKeyPairType(GordianKeyPairType.MAYO).build();
186     }
187 
188     /**
189      * Create mayoSpec.
190      *
191      * @return the SignatureSpec
192      */
193     default GordianSignatureSpec snova() {
194         return withKeyPairType(GordianKeyPairType.SNOVA).build();
195     }
196 
197     /**
198      * Create picnicSpec.
199      *
200      * @return the SignatureSpec
201      */
202     default GordianSignatureSpec picnic() {
203         return withKeyPairType(GordianKeyPairType.PICNIC).build();
204     }
205 
206     /**
207      * Create picnicSpec.
208      *
209      * @param pDigest the digestSpec
210      * @return the SignatureSpec
211      */
212     default GordianSignatureSpec picnic(final GordianDigestSpec pDigest) {
213         return withKeyPairType(GordianKeyPairType.PICNIC).withDigestSpec(pDigest).build();
214     }
215 
216     /**
217      * Create xmssSpec.
218      *
219      * @return the SignatureSpec
220      */
221     default GordianSignatureSpec xmss() {
222         return withKeyPairType(GordianKeyPairType.XMSS).build();
223     }
224 
225     /**
226      * Create xmssPHSpec.
227      *
228      * @return the SignatureSpec
229      */
230     default GordianSignatureSpec xmssph() {
231         return withKeyPairType(GordianKeyPairType.XMSS).withSignatureType(GordianSignatureType.PREHASH).build();
232     }
233 
234     /**
235      * Create lmsSpec.
236      *
237      * @return the SignatureSpec
238      */
239     default GordianSignatureSpec lms() {
240         return withKeyPairType(GordianKeyPairType.LMS).build();
241     }
242 
243     /**
244      * Create CompositeSpec.
245      *
246      * @param pSpecs the list of encryptorSpecs
247      * @return the encryptorSpec
248      */
249     default GordianSignatureSpec composite(final GordianSignatureSpec... pSpecs) {
250         return composite(Arrays.asList(pSpecs));
251     }
252 
253     /**
254      * Create CompositeSpec.
255      *
256      * @param pSpecs the list of encryptorSpecs
257      * @return the encryptorSpec
258      */
259     default GordianSignatureSpec composite(final List<GordianSignatureSpec> pSpecs) {
260         return withKeyPairType(GordianKeyPairType.COMPOSITE).withSignatureSpecs(pSpecs).build();
261     }
262 }