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.zip;
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.lock.GordianLock;
22  import io.github.tonywasher.joceanus.gordianknot.api.lock.GordianPasswordLockSpec;
23  
24  import java.io.File;
25  import java.io.InputStream;
26  import java.io.OutputStream;
27  
28  /**
29   * GordianKnot Zip Factory API.
30   */
31  public interface GordianZipFactory {
32      /**
33       * Create a keySetLock.
34       *
35       * @param pPassword the password
36       * @return the zipLock
37       * @throws GordianException on error
38       */
39      default GordianZipLock keySetZipLock(final char[] pPassword) throws GordianException {
40          return keySetZipLock(new GordianPasswordLockSpec(), pPassword);
41      }
42  
43      /**
44       * Create a keySetLock.
45       *
46       * @param pLockSpec the lockSpec
47       * @param pPassword the password
48       * @return the zipLock
49       * @throws GordianException on error
50       */
51      GordianZipLock keySetZipLock(GordianPasswordLockSpec pLockSpec,
52                                   char[] pPassword) throws GordianException;
53  
54      /**
55       * Create a factoryLock.
56       *
57       * @param pPassword the password
58       * @return the zipLock
59       * @throws GordianException on error
60       */
61      default GordianZipLock factoryZipLock(final char[] pPassword) throws GordianException {
62          return factoryZipLock(new GordianPasswordLockSpec(), pPassword);
63      }
64  
65      /**
66       * Create a factoryLock.
67       *
68       * @param pLockSpec the lockSpec
69       * @param pPassword the password
70       * @return the zipLock
71       * @throws GordianException on error
72       */
73      GordianZipLock factoryZipLock(GordianPasswordLockSpec pLockSpec,
74                                    char[] pPassword) throws GordianException;
75  
76      /**
77       * Create a keyPairZipLock.
78       *
79       * @param pKeyPair  the keyPair
80       * @param pPassword the password
81       * @return the zipLock
82       * @throws GordianException on error
83       */
84      default GordianZipLock keyPairZipLock(final GordianKeyPair pKeyPair,
85                                            final char[] pPassword) throws GordianException {
86          return keyPairZipLock(new GordianPasswordLockSpec(), pKeyPair, pPassword);
87      }
88  
89      /**
90       * Create a keyPairZipLock.
91       *
92       * @param pLockSpec the lockSpec
93       * @param pKeyPair  the keyPair
94       * @param pPassword the password
95       * @return the zipLock
96       * @throws GordianException on error
97       */
98      GordianZipLock keyPairZipLock(GordianPasswordLockSpec pLockSpec,
99                                    GordianKeyPair pKeyPair,
100                                   char[] pPassword) throws GordianException;
101 
102     /**
103      * Create a zipLock.
104      *
105      * @param pLock the keyPairLock
106      * @return the zipLock
107      * @throws GordianException on error
108      */
109     GordianZipLock zipLock(GordianLock<?> pLock) throws GordianException;
110 
111     /**
112      * Create a secure zipFile.
113      *
114      * @param pZipLock the zipLock to use
115      * @param pFile    the file details for the new zip file
116      * @return the zipFile
117      * @throws GordianException on error
118      */
119     GordianZipWriteFile createZipFile(GordianZipLock pZipLock,
120                                       File pFile) throws GordianException;
121 
122     /**
123      * Create a secure zipFile.
124      *
125      * @param pZipLock      the zipLock to use
126      * @param pOutputStream the output stream to write to
127      * @return the zipFile
128      * @throws GordianException on error
129      */
130     GordianZipWriteFile createZipFile(GordianZipLock pZipLock,
131                                       OutputStream pOutputStream) throws GordianException;
132 
133     /**
134      * Create a standard zipFile with no security.
135      *
136      * @param pFile the file details for the new zip file
137      * @return the zipFile
138      * @throws GordianException on error
139      */
140     GordianZipWriteFile createZipFile(File pFile) throws GordianException;
141 
142     /**
143      * Create a standard zipFile with no security.
144      *
145      * @param pOutputStream the output stream to write to
146      * @return the zipFile
147      */
148     GordianZipWriteFile createZipFile(OutputStream pOutputStream);
149 
150     /**
151      * Open an existing zipFile.
152      *
153      * @param pFile the file to read
154      * @return the zipFile
155      * @throws GordianException on error
156      */
157     GordianZipReadFile openZipFile(File pFile) throws GordianException;
158 
159     /**
160      * Open an existing zipFile.
161      *
162      * @param pInputStream the input stream to read from
163      * @return the zipFile
164      * @throws GordianException on error
165      */
166     GordianZipReadFile openZipFile(InputStream pInputStream) throws GordianException;
167 }