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