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.spec.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     GordianFactoryLock newFactoryLock(GordianFactory pFactoryToLock,
126                                       char[] pPassword) throws GordianException;
127 
128     /**
129      * Create a new factoryLock for a factory.
130      *
131      * @param pFactoryToLock the factory to lock
132      * @param pLockSpec      the locking spec
133      * @param pPassword      the password
134      * @return the factoryLock
135      * @throws GordianException on error
136      */
137     GordianFactoryLock newFactoryLock(GordianFactory pFactoryToLock,
138                                       GordianPasswordLockSpec pLockSpec,
139                                       char[] pPassword) throws GordianException;
140 
141     /**
142      * Create a new factoryLock.
143      *
144      * @param pFactoryType the factoryType
145      * @param pPassword    the password
146      * @return the factoryLock
147      * @throws GordianException on error
148      */
149     GordianFactoryLock newFactoryLock(GordianFactoryType pFactoryType,
150                                       char[] pPassword) throws GordianException;
151 
152     /**
153      * Create a new factoryLock for a new random factory.
154      *
155      * @param pLockSpec    the locking spec
156      * @param pFactoryType the factoryType
157      * @param pPassword    the password
158      * @return the factoryLock
159      * @throws GordianException on error
160      */
161     GordianFactoryLock newFactoryLock(GordianPasswordLockSpec pLockSpec,
162                                       GordianFactoryType pFactoryType,
163                                       char[] pPassword) throws GordianException;
164 
165     /**
166      * Resolve a factoryLock.
167      *
168      * @param pLockBytes the lockBytes
169      * @param pPassword  the password
170      * @return the resolved factoryLock
171      * @throws GordianException on error
172      */
173     GordianFactoryLock resolveFactoryLock(byte[] pLockBytes,
174                                           char[] pPassword) throws GordianException;
175 
176     /**
177      * Factory Lock.
178      */
179     interface GordianFactoryLock
180             extends GordianLock<GordianFactory> {
181         /**
182          * Obtain the factory.
183          *
184          * @return the factory
185          */
186         default GordianFactory getFactory() {
187             return getLockedObject();
188         }
189     }
190 }