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.lock;
18
19 import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20 import io.github.tonywasher.joceanus.gordianknot.api.keypair.GordianKeyPair;
21 import io.github.tonywasher.joceanus.gordianknot.api.keyset.GordianKeySet;
22
23 /**
24 * Lock Factory API.
25 */
26 public interface GordianLockFactory {
27 /**
28 * Create a new keySetLock for a keySet.
29 *
30 * @param pKeySetToLock the keySet to lock
31 * @param pPassword the password
32 * @return the keySet lock
33 * @throws GordianException on error
34 */
35 default GordianKeySetLock newKeySetLock(final GordianKeySet pKeySetToLock,
36 final char[] pPassword) throws GordianException {
37 return newKeySetLock(pKeySetToLock, new GordianPasswordLockSpec(), pPassword);
38 }
39
40 /**
41 * Create a new keySetLock for a keySet.
42 *
43 * @param pKeySetToLock the keySet to lock
44 * @param pLockSpec the locking spec
45 * @param pPassword the password
46 * @return the keySet lock
47 * @throws GordianException on error
48 */
49 GordianKeySetLock newKeySetLock(GordianKeySet pKeySetToLock,
50 GordianPasswordLockSpec pLockSpec,
51 char[] pPassword) throws GordianException;
52
53 /**
54 * Create a new keySetLock for a new random keySet.
55 *
56 * @param pPassword the password
57 * @return the keySet lock
58 * @throws GordianException on error
59 */
60 default GordianKeySetLock newKeySetLock(final char[] pPassword) throws GordianException {
61 return newKeySetLock(new GordianPasswordLockSpec(), pPassword);
62 }
63
64 /**
65 * Create a new keySetLock for a new random keySet.
66 *
67 * @param pLockSpec the locking spec
68 * @param pPassword the password
69 * @return the keySet lock
70 * @throws GordianException on error
71 */
72 GordianKeySetLock newKeySetLock(GordianPasswordLockSpec pLockSpec,
73 char[] pPassword) throws GordianException;
74
75 /**
76 * Resolve a keySetLock.
77 *
78 * @param pLockBytes the lockBytes
79 * @param pPassword the password
80 * @return the resolved keySetLock
81 * @throws GordianException on error
82 */
83 GordianKeySetLock resolveKeySetLock(byte[] pLockBytes,
84 char[] pPassword) throws GordianException;
85
86 /**
87 * Create a new keyPairLock.
88 *
89 * @param pKeyPair the keyPair
90 * @param pPassword the password
91 * @return the keySet lock
92 * @throws GordianException on error
93 */
94 default GordianKeyPairLock newKeyPairLock(final GordianKeyPair pKeyPair,
95 final char[] pPassword) throws GordianException {
96 return newKeyPairLock(new GordianPasswordLockSpec(), pKeyPair, pPassword);
97 }
98
99 /**
100 * Create a new keyPairLock.
101 *
102 * @param pLockSpec the locking spec
103 * @param pKeyPair the keyPair
104 * @param pPassword the password
105 * @return the keySet lock
106 * @throws GordianException on error
107 */
108 GordianKeyPairLock newKeyPairLock(GordianPasswordLockSpec pLockSpec,
109 GordianKeyPair pKeyPair,
110 char[] pPassword) throws GordianException;
111
112 /**
113 * Resolve a keySetLock.
114 *
115 * @param pLockBytes the lockBytes
116 * @param pKeyPair the keyPair
117 * @param pPassword the password
118 * @return the resolved keySetLock
119 * @throws GordianException on error
120 */
121 GordianKeyPairLock resolveKeyPairLock(byte[] pLockBytes,
122 GordianKeyPair pKeyPair,
123 char[] pPassword) throws GordianException;
124 }