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.agree.spec;
19
20 import io.github.tonywasher.joceanus.gordianknot.api.keypair.spec.GordianKeyPairSpec;
21
22 /**
23 * KeyPair Agreement Specification Builder.
24 */
25 public interface GordianAgreementSpecBuilder {
26 /**
27 * Define keyPairSpec.
28 *
29 * @param pSpec the spec
30 * @return the Builder
31 */
32 GordianAgreementSpecBuilder withKeyPairSpec(GordianKeyPairSpec pSpec);
33
34 /**
35 * Define agreementType.
36 *
37 * @param pType the agreementType
38 * @return the Builder
39 */
40 GordianAgreementSpecBuilder withAgreementType(GordianAgreementType pType);
41
42 /**
43 * Define kdf.
44 *
45 * @param pKDF the kdf
46 * @return the Builder
47 */
48 GordianAgreementSpecBuilder withKDF(GordianAgreementKDF pKDF);
49
50 /**
51 * Request confirm.
52 *
53 * @return the builder
54 */
55 GordianAgreementSpecBuilder withConfirm();
56
57 /**
58 * Build signatureSpec.
59 *
60 * @return the agreementSpec
61 */
62 GordianAgreementSpec build();
63
64 /**
65 * Create generic agreement.
66 *
67 * @param pKeyPairSpec the keyPairSpec
68 * @param pAgreeType the agreementType
69 * @param pKDFType the KDF type
70 * @return the agreementSpec
71 */
72 default GordianAgreementSpec agree(final GordianKeyPairSpec pKeyPairSpec,
73 final GordianAgreementType pAgreeType,
74 final GordianAgreementKDF pKDFType) {
75 return withKeyPairSpec(pKeyPairSpec).withAgreementType(pAgreeType).withKDF(pKDFType).build();
76 }
77
78 /**
79 * Create generic agreement.
80 *
81 * @param pKeyPairSpec the keyPairSpec
82 * @param pAgreeType the agreementType
83 * @param pKDFType the KDF type
84 * @param pConfirm withConfirm(true/false)
85 * @return the agreementSpec
86 */
87 default GordianAgreementSpec agree(final GordianKeyPairSpec pKeyPairSpec,
88 final GordianAgreementType pAgreeType,
89 final GordianAgreementKDF pKDFType,
90 final boolean pConfirm) {
91 withKeyPairSpec(pKeyPairSpec).withAgreementType(pAgreeType).withKDF(pKDFType);
92 if (pConfirm) {
93 withConfirm();
94 }
95 return build();
96 }
97
98 /**
99 * Create the KEM agreementSpec.
100 *
101 * @param pKeyPairSpec the keyPairSpec
102 * @param pKDFType the KDF type
103 * @return the Spec
104 */
105 default GordianAgreementSpec kem(final GordianKeyPairSpec pKeyPairSpec,
106 final GordianAgreementKDF pKDFType) {
107 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.KEM).withKDF(pKDFType).build();
108 }
109
110 /**
111 * Create the ANON agreementSpec.
112 *
113 * @param pKeyPairSpec the keyPairSpec
114 * @param pKDFType the KDF type
115 * @return the Spec
116 */
117 default GordianAgreementSpec anon(final GordianKeyPairSpec pKeyPairSpec,
118 final GordianAgreementKDF pKDFType) {
119 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.ANON).withKDF(pKDFType).build();
120 }
121
122 /**
123 * Create the Basic agreementSpec.
124 *
125 * @param pKeyPairSpec the keyPairSpec
126 * @param pKDFType the KDF type
127 * @return the Spec
128 */
129 default GordianAgreementSpec basic(final GordianKeyPairSpec pKeyPairSpec,
130 final GordianAgreementKDF pKDFType) {
131 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.BASIC).withKDF(pKDFType).build();
132 }
133
134 /**
135 * Create the signed agreementSpec.
136 *
137 * @param pKeyPairSpec the keyPairSpec
138 * @param pKDFType the KDF type
139 * @return the Spec
140 */
141 default GordianAgreementSpec signed(final GordianKeyPairSpec pKeyPairSpec,
142 final GordianAgreementKDF pKDFType) {
143 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.SIGNED).withKDF(pKDFType).build();
144 }
145
146 /**
147 * Create the MQV agreementSpec.
148 *
149 * @param pKeyPairSpec the keyPairSpec
150 * @param pKDFType the KDF type
151 * @return the Spec
152 */
153 default GordianAgreementSpec mqv(final GordianKeyPairSpec pKeyPairSpec,
154 final GordianAgreementKDF pKDFType) {
155 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.MQV).withKDF(pKDFType).build();
156 }
157
158 /**
159 * Create the MQVConfirm agreementSpec.
160 *
161 * @param pKeyPairSpec the keyPairSpec
162 * @param pKDFType the KDF type
163 * @return the Spec
164 */
165 default GordianAgreementSpec mqvConfirm(final GordianKeyPairSpec pKeyPairSpec,
166 final GordianAgreementKDF pKDFType) {
167 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.MQV).withKDF(pKDFType).withConfirm().build();
168 }
169
170 /**
171 * Create the Unified agreementSpec.
172 *
173 * @param pKeyPairSpec the keyPairSpec
174 * @param pKDFType the KDF type
175 * @return the Spec
176 */
177 default GordianAgreementSpec unified(final GordianKeyPairSpec pKeyPairSpec,
178 final GordianAgreementKDF pKDFType) {
179 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.UNIFIED).withKDF(pKDFType).build();
180 }
181
182 /**
183 * Create the unifiedConfirm agreementSpec.
184 *
185 * @param pKeyPairSpec the keyPairSpec
186 * @param pKDFType the KDF type
187 * @return the Spec
188 */
189 default GordianAgreementSpec unifiedConfirm(final GordianKeyPairSpec pKeyPairSpec,
190 final GordianAgreementKDF pKDFType) {
191 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.UNIFIED).withKDF(pKDFType).withConfirm().build();
192 }
193
194 /**
195 * Create the sm2 agreementSpec.
196 *
197 * @param pKeyPairSpec the keyPairSpec
198 * @param pKDFType the KDF type
199 * @return the Spec
200 */
201 default GordianAgreementSpec sm2(final GordianKeyPairSpec pKeyPairSpec,
202 final GordianAgreementKDF pKDFType) {
203 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.SM2).withKDF(pKDFType).build();
204 }
205
206 /**
207 * Create the sm2Confirm agreementSpec.
208 *
209 * @param pKeyPairSpec the keyPairSpec
210 * @param pKDFType the KDF type
211 * @return the Spec
212 */
213 default GordianAgreementSpec sm2Confirm(final GordianKeyPairSpec pKeyPairSpec,
214 final GordianAgreementKDF pKDFType) {
215 return withKeyPairSpec(pKeyPairSpec).withAgreementType(GordianAgreementType.SM2).withKDF(pKDFType).withConfirm().build();
216 }
217 }