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.encrypt.spec;
19  
20  import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpec;
21  import io.github.tonywasher.joceanus.gordianknot.api.digest.spec.GordianDigestSpecBuilder;
22  import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairType;
23  
24  import java.util.Arrays;
25  import java.util.List;
26  
27  /**
28   * Asymmetric Encryption Specification Builder.
29   */
30  public interface GordianEncryptorSpecBuilder {
31      /**
32       * Define keyPairType.
33       *
34       * @param pType the type
35       * @return the Builder
36       */
37      GordianEncryptorSpecBuilder withKeyPairType(GordianKeyPairType pType);
38  
39      /**
40       * Define digestSpec.
41       *
42       * @param pDigestSpec the digest spec
43       * @return the Builder
44       */
45      GordianEncryptorSpecBuilder withDigestSpec(GordianDigestSpec pDigestSpec);
46  
47      /**
48       * Define sm2EncryptionType.
49       *
50       * @param pType       the SM2 encryptionType
51       * @param pDigestSpec the digestSpec
52       * @return the Builder
53       */
54      GordianEncryptorSpecBuilder withSM2EncryptionSpec(GordianSM2EncryptionType pType,
55                                                        GordianDigestSpec pDigestSpec);
56  
57      /**
58       * Define encryptorSpec list.
59       *
60       * @param pSpecs the specs
61       * @return the builder
62       */
63      GordianEncryptorSpecBuilder withEncryptorSpecs(List<GordianEncryptorSpec> pSpecs);
64  
65      /**
66       * Access digestSpecBuilder.
67       *
68       * @return the digestSpec builder
69       */
70      GordianDigestSpecBuilder usingDigestSpecBuilder();
71  
72      /**
73       * Build encryptorSpec.
74       *
75       * @return the encryptorSpec
76       */
77      GordianEncryptorSpec build();
78  
79      /**
80       * Create RSA Encryptor.
81       *
82       * @param pSpec the digestSpec
83       * @return the encryptorSpec
84       */
85      default GordianEncryptorSpec rsa(final GordianDigestSpec pSpec) {
86          return withKeyPairType(GordianKeyPairType.RSA).withDigestSpec(pSpec).build();
87      }
88  
89      /**
90       * Create ElGamal Encryptor.
91       *
92       * @param pSpec the digestSpec
93       * @return the encryptorSpec
94       */
95      default GordianEncryptorSpec elGamal(final GordianDigestSpec pSpec) {
96          return withKeyPairType(GordianKeyPairType.ELGAMAL).withDigestSpec(pSpec).build();
97      }
98  
99      /**
100      * Create EC Encryptor.
101      *
102      * @return the encryptorSpec
103      */
104     default GordianEncryptorSpec ec() {
105         return withKeyPairType(GordianKeyPairType.EC).build();
106     }
107 
108     /**
109      * Create GOST Encryptor.
110      *
111      * @return the encryptorSpec
112      */
113     default GordianEncryptorSpec gost2012() {
114         return withKeyPairType(GordianKeyPairType.GOST).build();
115     }
116 
117     /**
118      * Create SM2 Encryptor.
119      *
120      * @return the encryptorSpec
121      */
122     default GordianEncryptorSpec sm2() {
123         return withKeyPairType(GordianKeyPairType.SM2).build();
124     }
125 
126     /**
127      * Create SM2 Encryptor.
128      *
129      * @param pType the sm2EncryptionType
130      * @param pSpec the digestSpec
131      * @return the encryptorSpec
132      */
133     default GordianEncryptorSpec sm2(final GordianSM2EncryptionType pType,
134                                      final GordianDigestSpec pSpec) {
135         return withKeyPairType(GordianKeyPairType.SM2).withSM2EncryptionSpec(pType, pSpec).build();
136     }
137 
138     /**
139      * Create CompositeSpec.
140      *
141      * @param pSpecs the list of encryptorSpecs
142      * @return the encryptorSpec
143      */
144     default GordianEncryptorSpec composite(final GordianEncryptorSpec... pSpecs) {
145         return composite(Arrays.asList(pSpecs));
146     }
147 
148     /**
149      * Create CompositeSpec.
150      *
151      * @param pSpecs the list of encryptorSpecs
152      * @return the encryptorSpec
153      */
154     default GordianEncryptorSpec composite(final List<GordianEncryptorSpec> pSpecs) {
155         return withKeyPairType(GordianKeyPairType.COMPOSITE).withEncryptorSpecs(pSpecs).build();
156     }
157 }