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.factory;
18  
19  import io.github.tonywasher.joceanus.gordianknot.api.base.GordianException;
20  import io.github.tonywasher.joceanus.gordianknot.api.cipher.GordianCipherFactory;
21  import io.github.tonywasher.joceanus.gordianknot.api.digest.GordianDigestFactory;
22  import io.github.tonywasher.joceanus.gordianknot.api.keyset.GordianKeySet;
23  import io.github.tonywasher.joceanus.gordianknot.api.keyset.GordianKeySetFactory;
24  import io.github.tonywasher.joceanus.gordianknot.api.lock.GordianLock;
25  import io.github.tonywasher.joceanus.gordianknot.api.lock.GordianLockFactory;
26  import io.github.tonywasher.joceanus.gordianknot.api.lock.GordianPasswordLockSpec;
27  import io.github.tonywasher.joceanus.gordianknot.api.mac.GordianMacFactory;
28  import io.github.tonywasher.joceanus.gordianknot.api.random.GordianRandomFactory;
29  import io.github.tonywasher.joceanus.gordianknot.api.zip.GordianZipFactory;
30  
31  /**
32   * Factory API.
33   */
34  public interface GordianFactory {
35      /**
36       * Obtain factory type.
37       *
38       * @return the factory type
39       */
40      GordianFactoryType getFactoryType();
41  
42      /**
43       * Obtain the Digest Factory.
44       *
45       * @return the digest factory
46       */
47      GordianDigestFactory getDigestFactory();
48  
49      /**
50       * Obtain the Cipher Factory.
51       *
52       * @return the cipher factory
53       */
54      GordianCipherFactory getCipherFactory();
55  
56      /**
57       * Obtain the Mac Factory.
58       *
59       * @return the Mac factory
60       */
61      GordianMacFactory getMacFactory();
62  
63      /**
64       * Obtain the keySet Factory.
65       *
66       * @return the keySet factory
67       */
68      GordianKeySetFactory getKeySetFactory();
69  
70      /**
71       * Obtain the random Factory.
72       *
73       * @return the random factory
74       */
75      GordianRandomFactory getRandomFactory();
76  
77      /**
78       * Obtain the Lock Factory.
79       *
80       * @return the lock factory
81       */
82      GordianLockFactory getLockFactory();
83  
84      /**
85       * Obtain the Zip Factory.
86       *
87       * @return the zip factory
88       */
89      GordianZipFactory getZipFactory();
90  
91      /**
92       * Obtain the async Factory.
93       *
94       * @return the async factory
95       */
96      GordianAsyncFactory getAsyncFactory();
97  
98      /**
99       * ReSeed the random number generator.
100      */
101     void reSeedRandom();
102 
103     /**
104      * Obtain the obfuscater.
105      *
106      * @return the obfuscater
107      */
108     GordianKnuthObfuscater getObfuscater();
109 
110     /**
111      * Obtain the embedded keySet.
112      *
113      * @return the keySet (or null)
114      */
115     GordianKeySet getEmbeddedKeySet();
116 
117     /**
118      * Create a new factoryLock.
119      *
120      * @param pFactoryToLock the factory to lock
121      * @param pPassword      the password
122      * @return the factoryLock
123      * @throws GordianException on error
124      */
125     default GordianFactoryLock newFactoryLock(final GordianFactory pFactoryToLock,
126                                               final char[] pPassword) throws GordianException {
127         /* Create the factoryLock */
128         return newFactoryLock(pFactoryToLock, new GordianPasswordLockSpec(), pPassword);
129     }
130 
131     /**
132      * Create a new factoryLock for a factory.
133      *
134      * @param pFactoryToLock the factory to lock
135      * @param pLockSpec      the locking spec
136      * @param pPassword      the password
137      * @return the factoryLock
138      * @throws GordianException on error
139      */
140     GordianFactoryLock newFactoryLock(GordianFactory pFactoryToLock,
141                                       GordianPasswordLockSpec pLockSpec,
142                                       char[] pPassword) throws GordianException;
143 
144     /**
145      * Create a new factoryLock.
146      *
147      * @param pFactoryType the factoryType
148      * @param pPassword    the password
149      * @return the factoryLock
150      * @throws GordianException on error
151      */
152     default GordianFactoryLock newFactoryLock(final GordianFactoryType pFactoryType,
153                                               final char[] pPassword) throws GordianException {
154         /* Create the factoryLock */
155         return newFactoryLock(new GordianPasswordLockSpec(), pFactoryType, pPassword);
156     }
157 
158     /**
159      * Create a new factoryLock for a new random factory.
160      *
161      * @param pLockSpec    the locking spec
162      * @param pFactoryType the factoryType
163      * @param pPassword    the password
164      * @return the factoryLock
165      * @throws GordianException on error
166      */
167     GordianFactoryLock newFactoryLock(GordianPasswordLockSpec pLockSpec,
168                                       GordianFactoryType pFactoryType,
169                                       char[] pPassword) throws GordianException;
170 
171     /**
172      * Resolve a factoryLock.
173      *
174      * @param pLockBytes the lockBytes
175      * @param pPassword  the password
176      * @return the resolved factoryLock
177      * @throws GordianException on error
178      */
179     GordianFactoryLock resolveFactoryLock(byte[] pLockBytes,
180                                           char[] pPassword) throws GordianException;
181 
182     /**
183      * Factory Lock.
184      */
185     interface GordianFactoryLock
186             extends GordianLock<GordianFactory> {
187         /**
188          * Obtain the factory.
189          *
190          * @return the factory
191          */
192         default GordianFactory getFactory() {
193             return getLockedObject();
194         }
195     }
196 }