-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(encrypt): hack compress encrypted with password
..as it not supported by Apache Commons Compress Next step, PR to Apache Commons Compress project #1
- Loading branch information
Showing
58 changed files
with
9,273 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/org/apache/commons/compress/MemoryLimitException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* If a stream checks for estimated memory allocation, and the estimate | ||
* goes above the memory limit, this is thrown. This can also be thrown | ||
* if a stream tries to allocate a byte array that is larger than | ||
* the allowable limit. | ||
* | ||
* @since 1.14 | ||
*/ | ||
public class MemoryLimitException extends IOException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
//long instead of int to account for overflow for corrupt files | ||
private final long memoryNeededInKb; | ||
private final int memoryLimitInKb; | ||
|
||
public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb) { | ||
super(buildMessage(memoryNeededInKb, memoryLimitInKb)); | ||
this.memoryNeededInKb = memoryNeededInKb; | ||
this.memoryLimitInKb = memoryLimitInKb; | ||
} | ||
|
||
public MemoryLimitException(final long memoryNeededInKb, final int memoryLimitInKb, final Exception e) { | ||
super(buildMessage(memoryNeededInKb, memoryLimitInKb), e); | ||
this.memoryNeededInKb = memoryNeededInKb; | ||
this.memoryLimitInKb = memoryLimitInKb; | ||
} | ||
|
||
public long getMemoryNeededInKb() { | ||
return memoryNeededInKb; | ||
} | ||
|
||
public int getMemoryLimitInKb() { | ||
return memoryLimitInKb; | ||
} | ||
|
||
private static String buildMessage(final long memoryNeededInKb, final int memoryLimitInKb) { | ||
return memoryNeededInKb + " kb of memory would be needed; limit was " | ||
+ memoryLimitInKb + " kb. " + | ||
"If the file is not corrupt, consider increasing the memory limit."; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/apache/commons/compress/PasswordRequiredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Exception thrown when trying to read an encrypted entry or file without | ||
* configuring a password. | ||
* @since 1.10 | ||
*/ | ||
public class PasswordRequiredException extends IOException { | ||
|
||
private static final long serialVersionUID = 1391070005491684483L; | ||
|
||
/** | ||
* Create a new exception. | ||
* | ||
* @param name name of the archive containing encrypted streams or | ||
* the encrypted file. | ||
*/ | ||
public PasswordRequiredException(final String name) { | ||
super("Cannot read encrypted content from " + name + " without a password."); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/apache/commons/compress/archivers/ArchiveEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Represents an entry of an archive. | ||
*/ | ||
public interface ArchiveEntry { | ||
|
||
/** | ||
* Gets the name of the entry in this archive. May refer to a file or directory or other item. | ||
* | ||
* <p>This method returns the raw name as it is stored inside of the archive.</p> | ||
* | ||
* @return The name of this entry in the archive. | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Gets the uncompressed size of this entry. May be -1 (SIZE_UNKNOWN) if the size is unknown | ||
* | ||
* @return the uncompressed size of this entry. | ||
*/ | ||
long getSize(); | ||
|
||
/** Special value indicating that the size is unknown */ | ||
long SIZE_UNKNOWN = -1; | ||
|
||
/** | ||
* Returns true if this entry refers to a directory. | ||
* | ||
* @return true if this entry refers to a directory. | ||
*/ | ||
boolean isDirectory(); | ||
|
||
/** | ||
* Gets the last modified date of this entry. | ||
* | ||
* @return the last modified date of this entry. | ||
* @since 1.1 | ||
*/ | ||
Date getLastModifiedDate(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/apache/commons/compress/archivers/sevenz/AES256Options.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.apache.commons.compress.archivers.sevenz; | ||
|
||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
public class AES256Options { | ||
byte[] password; | ||
byte[] salt = new byte[0]; | ||
byte[] iv = new byte[16]; | ||
int numCyclesPower = 19; | ||
|
||
public AES256Options(byte[] password) { | ||
this.password = password; | ||
new Random(Arrays.hashCode(password)).nextBytes(salt); | ||
new Random(Arrays.hashCode(password)).nextBytes(iv); | ||
} | ||
} |
Oops, something went wrong.