commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1653252 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/sevenz/ test/java/org/apache/commons/compress/archivers/sevenz/
Date Tue, 20 Jan 2015 14:24:34 GMT
Author: bodewig
Date: Tue Jan 20 14:24:34 2015
New Revision: 1653252

URL: http://svn.apache.org/r1653252
Log:
throw a special exception when there is no password for an encrpyted 7z archive - COMPRESS-298

Added:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java
  (with props)
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1653252&r1=1653251&r2=1653252&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Tue Jan 20 14:24:34 2015
@@ -80,6 +80,11 @@ The <action> type attribute can be add,u
         Improved error message when tar encounters a groupId that is
         too big to write without using the STAR or POSIX format.
       </action>
+      <action type="fix" date="2015-01-20" issue="COMPRESS-298">
+        SevenZFile now throws the specific PasswordRequiredException
+        when it encounters an encrypted stream but no password has
+        been specified.
+      </action>
     </release>
 
     <release version="1.9" date="2014-10-09"

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java?rev=1653252&r1=1653251&r2=1653252&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/AES256SHA256Decoder.java
Tue Jan 20 14:24:34 2015
@@ -54,7 +54,7 @@ class AES256SHA256Decoder extends CoderB
                 System.arraycopy(coder.properties, 2 + saltSize, iv, 0, ivSize);
 
                 if (passwordBytes == null) {
-                    throw new IOException("Cannot read encrypted files without a password");
+                    throw new PasswordRequiredException();
                 }
                 final byte[] aesKeyBytes;
                 if (numCyclesPower == 0x3f) {

Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java?rev=1653252&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java
(added)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java
Tue Jan 20 14:24:34 2015
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.compress.archivers.sevenz;
+
+import java.io.IOException;
+
+/**
+ * Exception thrown when trying to read an encrypted entry without
+ * configuring a password.
+ * @since 1.10
+ */
+public class PasswordRequiredException extends IOException {
+
+    public PasswordRequiredException() {
+        super("Cannot read encrypted files without a password");
+    }
+}

Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/PasswordRequiredException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java?rev=1653252&r1=1653251&r2=1653252&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
Tue Jan 20 14:24:34 2015
@@ -60,6 +60,15 @@ public class SevenZFileTest extends Abst
         }
     }
 
+    public void test7zDecryptUnarchiveWithoutPassword() throws Exception {
+        try {
+            test7zUnarchive(getFile("bla.encrypted.7z"), SevenZMethod.LZMA);
+            fail("Expected a PasswordRequiredException");
+        } catch (PasswordRequiredException ex) {
+            // expected
+        }
+    }
+
     private void test7zUnarchive(File f, SevenZMethod m) throws Exception {
         test7zUnarchive(f, m, null);
     }



Mime
View raw message