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.agree;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.cipher.GordianStreamCipher;
21 import io.github.tonywasher.joceanus.gordianknot.api.cipher.GordianSymCipher;
22 import io.github.tonywasher.joceanus.gordianknot.api.keyset.GordianKeySet;
23
24 /**
25 * Key Agreement Specification.
26 */
27 public interface GordianAgreement {
28 /**
29 * Obtain the agreementParameters.
30 *
31 * @return the parameters
32 */
33 GordianAgreementParams getAgreementParams();
34
35 /**
36 * Obtain agreement status.
37 *
38 * @return the agreement state
39 */
40 GordianAgreementStatus getStatus();
41
42 /**
43 * Obtain result.
44 *
45 * @return the result which can be any of
46 * <dl>
47 * <dt>GordianFactory</dt><dd>If a factory was agreed</dd>
48 * <dt>GordianSymCipher[2]</dt><dd>If a pair of symCiphers was agreed</dd>
49 * <dt>GordianStreamCipher[2]</dt><dd>If a pair of streamCiphers was agreed</dd>
50 * <dt>GordianKeySet</dt><dd>If a keySet was agreed</dd>
51 * <dt>byte[]</dt><dd>If a defined length byte array was agreed</dd>
52 * <dt>GordianException</dt><dd>If the agreement was rejected.</dd>
53 * </dl>
54 * @throws GordianException on error
55 */
56 Object getResult() throws GordianException;
57
58 /**
59 * Obtain keySet result.
60 *
61 * @return the result if it is available as a keySet, otherwise null
62 */
63 GordianKeySet getKeySetResult();
64
65 /**
66 * Obtain symCipherPair result.
67 *
68 * @return the result if it is available as a symCipherPair, otherwise null
69 */
70 GordianSymCipher[] getSymCipherPairResult();
71
72 /**
73 * Obtain streamCipherPair result.
74 *
75 * @return the result if it is available as a streamCipherPair, otherwise null
76 */
77 GordianStreamCipher[] getStreamCipherPairResult();
78
79 /**
80 * Obtain byteArray result.
81 *
82 * @return the result if it is available as a byteArray, otherwise null
83 */
84 byte[] getByteArrayResult();
85
86 /**
87 * Obtain Rejection result.
88 *
89 * @return the result if it is available as an exception, otherwise null
90 */
91 GordianException getRejectionResult();
92
93 /**
94 * Update parameters.
95 *
96 * @param pParams the updated parameters
97 * @throws GordianException on error
98 */
99 void updateParams(GordianAgreementParams pParams) throws GordianException;
100
101 /**
102 * Reject the agreement with error message.
103 *
104 * @param pError the error
105 * @throws GordianException on error
106 */
107 void setError(String pError) throws GordianException;
108
109 /**
110 * Is the agreement rejected?.
111 *
112 * @return true/false
113 */
114 boolean isRejected();
115
116 /**
117 * Obtain the next message.
118 *
119 * @return the next message (if any)
120 */
121 byte[] nextMessage();
122 }