| 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.apache.commons.compress.archivers.sevenz; |
| 20 | |
| 21 | import java.util.Arrays; |
| 22 | |
| 23 | /** |
| 24 | * Enumerates the (partially) supported compression/encryption methods used in 7z archives. |
| 25 | * <p> |
| 26 | * All methods with a {@code _FILTER} suffix are used as preprocessors with the goal of creating a better compression ratio with the compressor that comes next |
| 27 | * in the chain of methods. 7z will in general only allow them to be used together with a "real" compression method but Commons Compress doesn't enforce this. |
| 28 | * </p> |
| 29 | * <p> |
| 30 | * The {@code BCJ_} filters work on executable files for the given platform and convert relative addresses to absolute addresses in CALL instructions. This |
| 31 | * means they are only useful when applied to executables of the chosen platform. |
| 32 | * </p> |
| 33 | */ |
| 34 | public enum SevenZMethod { |
| 35 | |
| 36 | /** No compression at all. */ |
| 37 | COPY(new byte[] { (byte) 0x00 }), |
| 38 | |
| 39 | /** LZMA - only supported when reading. */ |
| 40 | LZMA(new byte[] { (byte) 0x03, (byte) 0x01, (byte) 0x01 }), |
| 41 | |
| 42 | /** LZMA2. */ |
| 43 | LZMA2(new byte[] { (byte) 0x21 }), |
| 44 | |
| 45 | /** Deflate. */ |
| 46 | DEFLATE(new byte[] { (byte) 0x04, (byte) 0x01, (byte) 0x08 }), |
| 47 | |
| 48 | /** |
| 49 | * Deflate64. |
| 50 | * |
| 51 | * @since 1.16 |
| 52 | */ |
| 53 | DEFLATE64(new byte[] { (byte) 0x04, (byte) 0x01, (byte) 0x09 }), |
| 54 | |
| 55 | /** BZIP2. */ |
| 56 | BZIP2(new byte[] { (byte) 0x04, (byte) 0x02, (byte) 0x02 }), |
| 57 | |
| 58 | /** |
| 59 | * AES encryption with a key length of 256 bit using SHA256 for hashes - only supported when reading. |
| 60 | */ |
| 61 | AES256SHA256(new byte[] { (byte) 0x06, (byte) 0xf1, (byte) 0x07, (byte) 0x01 }), |
| 62 | |
| 63 | /** |
| 64 | * BCJ x86 platform version 1. |
| 65 | * |
| 66 | * @since 1.8 |
| 67 | */ |
| 68 | BCJ_X86_FILTER(new byte[] { 0x03, 0x03, 0x01, 0x03 }), |
| 69 | |
| 70 | /** |
| 71 | * BCJ PowerPC platform. |
| 72 | * |
| 73 | * @since 1.8 |
| 74 | */ |
| 75 | BCJ_PPC_FILTER(new byte[] { 0x03, 0x03, 0x02, 0x05 }), |
| 76 | |
| 77 | /** |
| 78 | * BCJ I64 platform. |
| 79 | * |
| 80 | * @since 1.8 |
| 81 | */ |
| 82 | BCJ_IA64_FILTER(new byte[] { 0x03, 0x03, 0x04, 0x01 }), |
| 83 | |
| 84 | /** |
| 85 | * BCJ ARM platform. |
| 86 | * |
| 87 | * @since 1.8 |
| 88 | */ |
| 89 | BCJ_ARM_FILTER(new byte[] { 0x03, 0x03, 0x05, 0x01 }), |
| 90 | |
| 91 | /** |
| 92 | * BCJ ARM Thumb platform. |
| 93 | * |
| 94 | * @since 1.8 |
| 95 | */ |
| 96 | BCJ_ARM_THUMB_FILTER(new byte[] { 0x03, 0x03, 0x07, 0x01 }), |
| 97 | |
| 98 | /** |
| 99 | * BCJ Sparc platform. |
| 100 | * |
| 101 | * @since 1.8 |
| 102 | */ |
| 103 | BCJ_SPARC_FILTER(new byte[] { 0x03, 0x03, 0x08, 0x05 }), |
| 104 | |
| 105 | /** |
| 106 | * Delta filter. |
| 107 | * |
| 108 | * @since 1.8 |
| 109 | */ |
| 110 | DELTA_FILTER(new byte[] { 0x03 }); |
| 111 | |
| 112 | static SevenZMethod byId(final byte[] id) { |
| 113 | for (final SevenZMethod method : SevenZMethod.class.getEnumConstants()) { |
| 114 | if (Arrays.equals(method.id, id)) { |
| 115 | return method; |
| 116 | } |
| 117 | } |
| 118 | return null; |
| 119 | } |
| 120 | |
| 121 | private final byte[] id; |
| 122 | |
| 123 | SevenZMethod(final byte[] id) { |
| 124 | this.id = id; |
| 125 | } |
| 126 | |
| 127 | byte[] getId() { |
| 128 | return Arrays.copyOf(id, id.length); |
| 129 | } |
| 130 | } |