1414 * limitations under the License.
1515 */
1616
17- package com .android .apksigner . core ;
17+ package com .android .apksig ;
1818
19+ import com .android .apksig .apk .ApkFormatException ;
20+ import com .android .apksig .util .DataSink ;
21+ import com .android .apksig .util .DataSource ;
1922import java .io .Closeable ;
2023import java .io .IOException ;
2124import java .security .InvalidKeyException ;
25+ import java .security .NoSuchAlgorithmException ;
2226import java .security .SignatureException ;
2327import java .util .List ;
2428
25- import com .android .apksigner .core .util .DataSink ;
26- import com .android .apksigner .core .util .DataSource ;
27-
2829/**
2930 * APK signing logic which is independent of how input and output APKs are stored, parsed, and
3031 * generated.
3132 *
3233 * <p><h3>Operating Model</h3>
3334 *
3435 * The abstract operating model is that there is an input APK which is being signed, thus producing
35- * an output APK. In reality, there may be just an output APK being built from scratch, or the input APK and
36- * the output APK may be the same file. Because this engine does not deal with reading and writing
37- * files, it can handle all of these scenarios.
36+ * an output APK. In reality, there may be just an output APK being built from scratch, or the input
37+ * APK and the output APK may be the same file. Because this engine does not deal with reading and
38+ * writing files, it can handle all of these scenarios.
3839 *
3940 * <p>The engine is stateful and thus cannot be used for signing multiple APKs. However, once
4041 * the engine signed an APK, the engine can be used to re-sign the APK after it has been modified.
8889 * documentation of each method about the deadlines for performing the tasks requested by the
8990 * method.
9091 *
91- * <p><h3 id="incremental">Incremental Operation</h3>
92+ * <p><h3 id="incremental">Incremental Operation</h3></a>
9293 *
9394 * The engine supports incremental operation where a signed APK is produced, then modified and
9495 * re-signed. This may be useful for IDEs, where an app is frequently re-signed after small changes
108109 * not invoked. In this mode, the engine has less control over output because it cannot request that
109110 * some JAR entries are not output. Nevertheless, the engine will attempt to make the output APK
110111 * signed and will report an error if cannot do so.
112+ *
113+ * @see <a href="https://source.android.com/security/apksigning/index.html">Application Signing</a>
111114 */
112115public interface ApkSignerEngine extends Closeable {
113116
@@ -118,9 +121,12 @@ public interface ApkSignerEngine extends Closeable {
118121 * @param apkSigningBlock APK signing block of the input APK. The provided data source is
119122 * guaranteed to not be used by the engine after this method terminates.
120123 *
124+ * @throws IOException if an I/O error occurs while reading the APK Signing Block
125+ * @throws ApkFormatException if the APK Signing Block is malformed
121126 * @throws IllegalStateException if this engine is closed
122127 */
123- void inputApkSigningBlock (DataSource apkSigningBlock ) throws IllegalStateException ;
128+ void inputApkSigningBlock (DataSource apkSigningBlock )
129+ throws IOException , ApkFormatException , IllegalStateException ;
124130
125131 /**
126132 * Indicates to this engine that the specified JAR entry was encountered in the input APK.
@@ -176,19 +182,25 @@ InputJarEntryInstructions.OutputPolicy inputJarEntryRemoved(String entryName)
176182 /**
177183 * Indicates to this engine that all JAR entries have been output.
178184 *
179- *
180185 * @return request to add JAR signature to the output or {@code null} if there is no need to add
181186 * a JAR signature. The request will contain additional JAR entries to be output. The
182187 * request must be fulfilled before
183188 * {@link #outputZipSections(DataSource, DataSource, DataSource)} is invoked.
184189 *
190+ * @throws ApkFormatException if the APK is malformed in a way which is preventing this engine
191+ * from producing a valid signature. For example, if the engine uses the provided
192+ * {@code META-INF/MANIFEST.MF} as a template and the file is malformed.
193+ * @throws NoSuchAlgorithmException if a signature could not be generated because a required
194+ * cryptographic algorithm implementation is missing
185195 * @throws InvalidKeyException if a signature could not be generated because a signing key is
186196 * not suitable for generating the signature
187- * @throws SignatureException if an error occurred while generating the JAR signature
197+ * @throws SignatureException if an error occurred while generating a signature
188198 * @throws IllegalStateException if there are unfulfilled requests, such as to inspect some JAR
189199 * entries, or if the engine is closed
190200 */
191- OutputJarSignatureRequest outputJarEntries () throws InvalidKeyException , SignatureException ;
201+ OutputJarSignatureRequest outputJarEntries ()
202+ throws ApkFormatException , NoSuchAlgorithmException , InvalidKeyException ,
203+ SignatureException , IllegalStateException ;
192204
193205 /**
194206 * Indicates to this engine that the ZIP sections comprising the output APK have been output.
@@ -207,16 +219,23 @@ InputJarEntryInstructions.OutputPolicy inputJarEntryRemoved(String entryName)
207219 * {@link #outputDone()} is invoked.
208220 *
209221 * @throws IOException if an I/O error occurs while reading the provided ZIP sections
222+ * @throws ApkFormatException if the provided APK is malformed in a way which prevents this
223+ * engine from producing a valid signature. For example, if the APK Signing Block
224+ * provided to the engine is malformed.
225+ * @throws NoSuchAlgorithmException if a signature could not be generated because a required
226+ * cryptographic algorithm implementation is missing
210227 * @throws InvalidKeyException if a signature could not be generated because a signing key is
211228 * not suitable for generating the signature
212- * @throws SignatureException if an error occurred while generating the APK's signature
229+ * @throws SignatureException if an error occurred while generating a signature
213230 * @throws IllegalStateException if there are unfulfilled requests, such as to inspect some JAR
214231 * entries or to output JAR signature, or if the engine is closed
215232 */
216233 OutputApkSigningBlockRequest outputZipSections (
217234 DataSource zipEntries ,
218235 DataSource zipCentralDirectory ,
219- DataSource zipEocd ) throws IOException , InvalidKeyException , SignatureException ;
236+ DataSource zipEocd )
237+ throws IOException , ApkFormatException , NoSuchAlgorithmException ,
238+ InvalidKeyException , SignatureException , IllegalStateException ;
220239
221240 /**
222241 * Indicates to this engine that the signed APK was output.
0 commit comments