You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/08/11 11:56:08 UTC
(commons-compress) 04/04: [7-Zip] AES256Options now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.
This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 378eb82181c26f1550f1f7c42c981dd355209a94
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 11 07:55:56 2026 -0400
[7-Zip] AES256Options now throws ArchiveException instead of instead of
IllegalArgumetException/IllegalStateException.
- AES256SHA256Decoder now throws ArchiveException instead of instead of
IllegalArgumetException/IllegalStateException.
- SevenZMethodConfiguration now throws ArchiveException instead of
instead of IllegalArgumetException/IllegalStateException.
- SevenZOutputFile now throws ArchiveException instead of instead of
IllegalArgumetException/IllegalStateException.
---
src/changes/changes.xml | 46 ++++++++++++----------
.../compress/archivers/sevenz/AES256Options.java | 23 ++++++-----
.../archivers/sevenz/AES256SHA256Decoder.java | 15 ++++---
.../sevenz/SevenZMethodConfiguration.java | 11 ++++--
.../archivers/sevenz/SevenZOutputFile.java | 8 ++--
.../archivers/sevenz/SevenZArchiveEntryTest.java | 11 +++---
.../sevenz/SevenZMethodConfigurationTest.java | 20 +++++-----
7 files changed, 73 insertions(+), 61 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ce248afde..7a586669b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,7 +62,11 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[7-Zip] Reject short LZMA properties and oversized dictionary in LZMADecoder (#784).</action>
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[7-Zip] Fix copyOfRange end index in x0017 strong encryption header (#786).</action>
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[7-Zip] Fix packed stream count check in SevenZFile.sanityCheckUnpackInfo (#791).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZFile.getInputStream(SevenZArchiveEntry) now throws ArchiveException instead of IllehalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZFile.getInputStream(SevenZArchiveEntry) now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] AES256Options now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] AES256SHA256Decoder now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZMethodConfiguration now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[7-Zip] SevenZOutputFile now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX bzip2 -->
<action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[BZip2] BZip2CompressorInputStream now throw CompressorException (a subclass of IOException) for invalid or corrupted data, providing more specific error reporting.</action>
<action type="fix" dev="pkarwasz" due-to="Tyler Nighswander, Piotr P. Karwasz">[BZip2] BZip2 input streams treat Huffman codes longer than 20 bits as corrupted data, matching the behavior of the reference implementation.</action>
@@ -73,12 +77,12 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">[Dump] Fix DumpArchiveInputStream to correctly handle file names up to 255 bytes #711.</action>
<action type="fix" dev="ggregory" due-to="Philip Betzler-Braun, Gary Gregory, Piotr P. Karwasz" issue="COMPRESS-712">[Dump] Unsanitized read causes IndexOutOfBoundsException in #749.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory, KALI 834X">[Dump] DumpArchiveEntry rejects out-of-range directory header count (#781).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[Dump] DumpArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[Dump] TapeArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[Dump] DumpArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[Dump] TapeArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX zip -->
<action type="fix" dev="ggregory" due-to="Dominik Stadler, Gary Gregory" issue="COMPRESS-598">[Zip] ZipArchiveInputStream.read(byte[], int, int) now throws an IOException instead of a NullPointerException.</action>
- <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Zip] ZipFile.createBoundedInputStream(long, long) now throws an ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Zip] ZipFile.getContentBeforeFirstLocalFileHeader() now throws an ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Zip] ZipFile.createBoundedInputStream(long, long) now throws an ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Zip] ZipFile.getContentBeforeFirstLocalFileHeader() now throws an ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">[Zip] ExplodingInputStream now throws ArchiveException instead of ArithmeticException.</action>
<action type="fix" dev="ggregory" due-to="Tyler Nighswander, Gary Gregory">[Zip] ZipArchiveInputStream.read() now throws an IOException instead of java.lang.ArrayIndexOutOfBoundsException.</action>
<action type="fix" dev="ggregory" due-to="Stanislav Fort, Gary Gregory">[Zip] ZipArchiveInputStream now throws an MemoryLimitException instead of ArchiveException, or OutOfMemoryError when running with low memory settings set on the command line.</action>
@@ -98,26 +102,26 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory, KALI 834X">[TAR] Reject tar sparse blocks larger than the entry size (#780).</action>
<action type="fix" dev="ggregory" due-to="OldTruckDriver, Gary Gregory" issue="COMPRESS-724">[TAR] Fix TAR PAX 1.x sparse header alignment (#775).</action>
<action type="fix" dev="ggregory" due-to="subbudvk, Gary Gregory" issue="COMPRESS-723">[TAR] TAR PAX header parsing: enforce memory bound to mitigate resource exhaustion from oversized headers (#770).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDataOffset(long) now throw ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDevMajor(int) now throw ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDevMinor(int) now throw ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setSize(long) now throw ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.addPaxHeader(String, String) now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDataOffset(long) now throw ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDevMajor(int) now throw ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setDevMinor(int) now throw ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.setSize(long) now throw ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveEntry.addPaxHeader(String, String) now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TAR ParsingUtils now throws the IOException subclass CompressException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveOutputStream now throws ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarUtils now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveOutputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[TAR] TarUtils now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX ar -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">[AR] ArArchiveInputStream.readGNUStringTable(byte[], int, int) now provides a better exception message, wrapping the underlying exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">[AR] ArArchiveInputStream.read(byte[], int, int) now throws ArchiveException instead of ArithmeticException.</action>
<action type="fix" dev="pkarwasz" due-to="Tyler Nighswander">[AR] Simplify handling of special AR records in ArArchiveInputStream.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">[AR] Most ArArchiveEntry constructors now throws the IOException subclass ArchiveException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[AR] ArArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[AR] ArArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX arj -->
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">[ARJ] Correct byte accounting and truncation errors in ARJ input stream.</action>
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">[ARJ] Add strict header validation in ARJ input stream and `selfExtracting` option.</action>
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[ARJ] Reject missing main header in ArjArchiveInputStream.readMainHeader (#793).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[ARJ] ArjArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[ARJ] ArjArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX unpack200 -->
<action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav Fort">[Unpack200] org.apache.commons.compress.harmony.unpack200 now throws Pack200Exception, IllegalArgumentException, and IllegalStateException instead of other runtime exceptions and Error.</action>
<action type="fix" dev="pkarwasz" due-to="Piotr P. Karwasz">[Unpack200] Enforce strict attribute layout parsing in Pack200.</action>
@@ -136,8 +140,8 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" issue="COMPRESS-711" dev="pkarwasz" due-to="Piotr P. Karwasz">[Cpio] Fix checksum calculation in CpioArchiveInputStream when reading with a non-zero offset.</action>
<action type="fix" issue="COMPRESS-718" dev="ggregory" due-to="Anay Wadhera, Gary Gregory">[Cpio] CpioArchiveEntry does not allow files over 4GB in OLD_ASCII format.</action>
<action type="fix" dev="ggregory" due-to="Christopher Linke, Gary Gregory">[Cpio] Throw ArchiveException instead of EOFException when CPIO name size less than or equal to 0 #771.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[Cpio] CpioArchiveEntry now throws ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[Cpio] CpioArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[Cpio] CpioArchiveEntry now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[Cpio] CpioArchiveInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX gzip -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">[GZip] GzipParameters.setOperatingSystem(int) now throws CompressorException on illegal input.</action>
<action type="fix" issue="COMPRESS-705" dev="ggregory" due-to="Mario Fredenhagen, Gary Gregory">[GZip] GZip IOException: Extra subfield length exceeds remaining bytes in extra field; use new option GzipCompressorInputStream.Builder.setIgnoreExtraField(boolean).</action>
@@ -147,10 +151,10 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[Deflate64] Reject invalid literal/length and distance codes in Deflate64 decoder (#785).</action>
<!-- FIX lz77 -->
<action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">[LZ77] Reject back-reference offset larger than the window in lz77 decoder class AbstractLZ77CompressorInputStream (#797).</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] AbstractLZ77CompressorInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] LZ77Compressor.prefill(byte[]) now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] AbstractLZ77CompressorInputStream now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ77] LZ77Compressor.prefill(byte[]) now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX lz4 -->
- <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ4] BlockLZ4CompressorOutputStream.prefill(byte[], int, int) now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">[LZ4] BlockLZ4CompressorOutputStream.prefill(byte[], int, int) now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- FIX general -->
<action type="fix" dev="ggregory" due-to="Piotr P. Karwasz, Gary Gregory">Add missing Javadoc @since tag to org.apache.commons.compress.compressors.lz77support.LZ77Compressor.AbstractReference.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Classes in org.apache.commons.compress.archivers now throw a subclass of IOException called ArchiveException instead of IOException when a formatting problem is found.</action>
@@ -187,7 +191,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add and use ArchiveException.requireNonNegative(int, Supplier<String>)</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add and use ArchiveException.requireNonNegative(long, String)</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add and use ArchiveException.requireNonNegative(long, Supplier<String>)</action>
- <action type="fix" dev="ggregory" due-to="Gary Gregory">ArchiveStreamFactory now throws ArchiveException instead of IllegalArgumentException.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">ArchiveStreamFactory now throws ArchiveException instead of instead of IllegalArgumetException/IllegalStateException.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add MemoryLimitException.MemoryLimitException(long, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add CompressException.CompressException(String, Object...).</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256Options.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256Options.java
index 919a1ea14..ccb58e570 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256Options.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256Options.java
@@ -27,8 +27,10 @@
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
+import org.apache.commons.compress.archivers.ArchiveException;
+
/**
- * Options for {@link SevenZMethod#AES256SHA256} encoder
+ * Options for {@link SevenZMethod#AES256SHA256} encoder.
*
* @since 1.23
* @see AES256SHA256Decoder
@@ -45,12 +47,12 @@ static SecretKeySpec newSecretKeySpec(final byte[] bytes) {
return new SecretKeySpec(bytes, ALGORITHM);
}
- private static byte[] randomBytes(final int size) {
+ private static byte[] randomBytes(final int size) throws ArchiveException {
final byte[] bytes = new byte[size];
try {
SecureRandom.getInstanceStrong().nextBytes(bytes);
} catch (final NoSuchAlgorithmException e) {
- throw new IllegalStateException("No strong secure random available to generate strong AES key", e);
+ throw new ArchiveException("No strong secure random available to generate strong AES key.", (Throwable) e);
}
return bytes;
}
@@ -63,9 +65,12 @@ private static byte[] randomBytes(final int size) {
private final Cipher cipher;
/**
+ * Creates a new AES256Options with a random salt and IV.
+ *
* @param password password used for encryption.
+ * @throws ArchiveException No strong secure random available to generate strong AES key.
*/
- AES256Options(final char[] password) {
+ AES256Options(final char[] password) throws ArchiveException {
this(password, EMPTY_BYTE_ARRAY, randomBytes(16), 19);
}
@@ -75,22 +80,20 @@ private static byte[] randomBytes(final int size) {
* @param iv Initialization Vector (IV) used by cipher algorithm.
* @param numCyclesPower another password security enforcer parameter that controls the cycles of password hashing. More the this number is high, more
* security you'll have but also high CPU usage.
+ * @throws ArchiveException Encryption error (Check JCE Unlimited Strength Jurisdiction Policy Files installation).
*/
- AES256Options(final char[] password, final byte[] salt, final byte[] iv, final int numCyclesPower) {
+ AES256Options(final char[] password, final byte[] salt, final byte[] iv, final int numCyclesPower) throws ArchiveException {
this.salt = salt;
this.iv = iv;
this.numCyclesPower = numCyclesPower;
-
// NOTE: for security purposes, password is wrapped in a Cipher as soon as possible to not stay in memory
final byte[] aesKeyBytes = AES256SHA256Decoder.sha256Password(password, numCyclesPower, salt);
final SecretKey aesKey = newSecretKeySpec(aesKeyBytes);
-
try {
cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, aesKey, new IvParameterSpec(iv));
- } catch (final GeneralSecurityException generalSecurityException) {
- throw new IllegalStateException("Encryption error (do you have the JCE Unlimited Strength Jurisdiction Policy Files installed?)",
- generalSecurityException);
+ } catch (final GeneralSecurityException e) {
+ throw new ArchiveException("Encryption error (Check JCE Unlimited Strength Jurisdiction Policy Files installation).", (Throwable) e);
}
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
index bf82077ab..4c936d6cc 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
@@ -115,9 +115,8 @@ private CipherInputStream init() throws IOException {
cipherInputStream = new CipherInputStream(in, cipher);
isInitialized = true;
return cipherInputStream;
- } catch (final GeneralSecurityException generalSecurityException) {
- throw new IllegalStateException("Decryption error (do you have the JCE Unlimited Strength Jurisdiction Policy Files installed?)",
- generalSecurityException);
+ } catch (final GeneralSecurityException e) {
+ throw new ArchiveException("Decryption error (Check JCE Unlimited Strength Jurisdiction Policy Files installation).", (Throwable) e);
}
}
@@ -196,12 +195,12 @@ public void write(final int b) throws IOException {
}
}
- static byte[] sha256Password(final byte[] password, final int numCyclesPower, final byte[] salt) {
+ static byte[] sha256Password(final byte[] password, final int numCyclesPower, final byte[] salt) throws ArchiveException {
final MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-256");
- } catch (final NoSuchAlgorithmException noSuchAlgorithmException) {
- throw new IllegalStateException("SHA-256 is unsupported by your Java implementation", noSuchAlgorithmException);
+ } catch (final NoSuchAlgorithmException e) {
+ throw new ArchiveException("SHA-256 is unsupported by your Java implementation", (Throwable) e);
}
final byte[] extra = new byte[8];
for (long j = 0; j < 1L << numCyclesPower; j++) {
@@ -218,12 +217,12 @@ static byte[] sha256Password(final byte[] password, final int numCyclesPower, fi
return digest.digest();
}
- static byte[] sha256Password(final char[] password, final int numCyclesPower, final byte[] salt) {
+ static byte[] sha256Password(final char[] password, final int numCyclesPower, final byte[] salt) throws ArchiveException {
return sha256Password(utf16Decode(password), numCyclesPower, salt);
}
/**
- * Convenience method that encodes Unicode characters into bytes in UTF-16 (little-endian byte order) charset
+ * Convenience method that encodes Unicode characters into bytes in UTF-16 (little-endian byte order) charset.
*
* @param chars characters to encode.
* @return encoded characters.
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfiguration.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfiguration.java
index 736002552..eb96ea26c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfiguration.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfiguration.java
@@ -20,6 +20,8 @@
import java.util.Objects;
+import org.apache.commons.compress.archivers.ArchiveException;
+
/**
* Combines a SevenZMethod with configuration options for the method.
*
@@ -72,8 +74,9 @@ public class SevenZMethodConfiguration {
* Doesn't configure any additional options.
*
* @param method The method to use.
+ * @throws ArchiveException if the method can't be configured.
*/
- public SevenZMethodConfiguration(final SevenZMethod method) {
+ public SevenZMethodConfiguration(final SevenZMethod method) throws ArchiveException {
this(method, null);
}
@@ -82,13 +85,13 @@ public SevenZMethodConfiguration(final SevenZMethod method) {
*
* @param method The method to use.
* @param options The options to use.
- * @throws IllegalArgumentException if the method doesn't understand the options specified.
+ * @throws ArchiveException if the method doesn't understand the options specified.
*/
- public SevenZMethodConfiguration(final SevenZMethod method, final Object options) {
+ public SevenZMethodConfiguration(final SevenZMethod method, final Object options) throws ArchiveException {
this.method = method;
this.options = options;
if (options != null && !Coders.findByMethod(method).isOptionInstance(options)) {
- throw new IllegalArgumentException("The " + method + " method doesn't support options of type " + options.getClass());
+ throw new ArchiveException("The " + method + " method doesn't support options of type " + options.getClass());
}
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
index c2abce6f5..136fa3e3f 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
@@ -334,10 +334,9 @@ public void finish() throws IOException {
channel.write(bb);
}
- private Iterable<? extends SevenZMethodConfiguration> getContentMethods(final SevenZArchiveEntry entry) {
+ private Iterable<? extends SevenZMethodConfiguration> getContentMethods(final SevenZArchiveEntry entry) throws ArchiveException {
final Iterable<? extends SevenZMethodConfiguration> ms = entry.getContentMethods();
Iterable<? extends SevenZMethodConfiguration> iter = ms == null ? contentMethods : ms;
-
if (aes256Options != null) {
// prepend encryption
iter = Stream
@@ -395,8 +394,9 @@ public void putArchiveEntry(final SevenZArchiveEntry archiveEntry) {
* </p>
*
* @param method The default compression method.
+ * @throws ArchiveException if the method can't be configured.
*/
- public void setContentCompression(final SevenZMethod method) {
+ public void setContentCompression(final SevenZMethod method) throws ArchiveException {
setContentMethods(Collections.singletonList(new SevenZMethodConfiguration(method)));
}
@@ -420,7 +420,7 @@ public void setContentMethods(final Iterable<? extends SevenZMethodConfiguration
private CountingOutputStream setupFileOutputStream() throws IOException {
if (files.isEmpty()) {
- throw new IllegalStateException("No current 7z entry");
+ throw new ArchiveException("No current 7z entry");
}
// doesn't need to be closed, just wraps the instance field channel
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
index 1c84671bc..c3b6d02dd 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntryTest.java
@@ -22,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.apache.commons.compress.archivers.ArchiveException;
import org.junit.jupiter.api.Test;
/**
@@ -30,7 +31,7 @@
class SevenZArchiveEntryTest {
@Test
- void testMethodConfigurationMattersInEquals() {
+ void testMethodConfigurationMattersInEquals() throws ArchiveException {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
final SevenZArchiveEntry z3 = new SevenZArchiveEntry();
@@ -44,7 +45,7 @@ void testMethodConfigurationMattersInEquals() {
}
@Test
- void testMethodOrderMattersInEquals() {
+ void testMethodOrderMattersInEquals() throws ArchiveException {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.LZMA2), new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER));
@@ -54,7 +55,7 @@ void testMethodOrderMattersInEquals() {
}
@Test
- void testNoMethodsIsDifferentFromSomeMethods() {
+ void testNoMethodsIsDifferentFromSomeMethods() throws ArchiveException {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
z2.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
@@ -63,7 +64,7 @@ void testNoMethodsIsDifferentFromSomeMethods() {
}
@Test
- void testOneMethodsIsDifferentFromTwoMethods() {
+ void testOneMethodsIsDifferentFromTwoMethods() throws ArchiveException {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.COPY));
@@ -73,7 +74,7 @@ void testOneMethodsIsDifferentFromTwoMethods() {
}
@Test
- void testSameMethodsYieldEqualEntries() {
+ void testSameMethodsYieldEqualEntries() throws ArchiveException {
final SevenZArchiveEntry z1 = new SevenZArchiveEntry();
final SevenZArchiveEntry z2 = new SevenZArchiveEntry();
z1.setContentMethods(new SevenZMethodConfiguration(SevenZMethod.DELTA_FILTER), new SevenZMethodConfiguration(SevenZMethod.LZMA2));
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfigurationTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfigurationTest.java
index a382907b9..e4fc20206 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfigurationTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfigurationTest.java
@@ -22,54 +22,56 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.apache.commons.compress.archivers.ArchiveException;
+import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.tukaani.xz.LZMA2Options;
class SevenZMethodConfigurationTest {
@Test
- void testShouldAllowLZMA2OptionsForLZMA() {
+ void testShouldAllowLZMA2OptionsForLZMA() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA, new LZMA2Options()).getOptions());
}
@Test
- void testShouldAllowLZMA2OptionsForLZMA2() {
+ void testShouldAllowLZMA2OptionsForLZMA2() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2, new LZMA2Options()).getOptions());
}
@Test
- void testShouldAllowNullOptions() {
+ void testShouldAllowNullOptions() throws ArchiveException {
assertNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2, null).getOptions());
}
@Test
- void testShouldAllowNumberForBzip2() {
+ void testShouldAllowNumberForBzip2() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.BZIP2, 42).getOptions());
}
@Test
- void testShouldAllowNumberForDeflate() {
+ void testShouldAllowNumberForDeflate() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.DEFLATE, 42).getOptions());
}
@Test
- void testShouldAllowNumberForLZMA() {
+ void testShouldAllowNumberForLZMA() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA, 42).getOptions());
}
@Test
- void testShouldAllowNumberForLZMA2() {
+ void testShouldAllowNumberForLZMA2() throws ArchiveException {
assertNotNull(new SevenZMethodConfiguration(SevenZMethod.LZMA2, 42).getOptions());
}
@Test
void testShouldNotAllowStringOptionsForLZMA() {
- assertThrows(IllegalArgumentException.class, () -> new SevenZMethodConfiguration(SevenZMethod.LZMA, ""));
+ assertThrows(ArchiveException.class, () -> new SevenZMethodConfiguration(SevenZMethod.LZMA, StringUtils.EMPTY));
}
@Test
void testShouldNotAllowStringOptionsForLZMA2() {
- assertThrows(IllegalArgumentException.class, () -> new SevenZMethodConfiguration(SevenZMethod.LZMA2, ""));
+ assertThrows(ArchiveException.class, () -> new SevenZMethodConfiguration(SevenZMethod.LZMA2, StringUtils.EMPTY));
}
}