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.zip;
20
21 import java.util.zip.ZipException;
22
23 /**
24 * X.509 Certificate ID and Signature for central directory (0x0016).
25 *
26 * <p>
27 * This field contains the information about which certificate in the PKCS#7 store was used to sign the central directory structure. When the Central Directory
28 * Encryption feature is enabled for a ZIP file, this record will appear in the Archive Extra Data Record, otherwise it will appear in the first central
29 * directory record.
30 * </p>
31 *
32 * <p>
33 * Note: all fields stored in Intel low-byte/high-byte order.
34 * </p>
35 *
36 * <pre>
37 * Value Size Description
38 * ----- ---- -----------
39 * (CDID) 0x0016 2 bytes Tag for this "extra" block type
40 * TSize 2 bytes Size of data that follows
41 * RCount 4 bytes Number of recipients. (inferred)
42 * HashAlg 2 bytes Hash algorithm identifier. (inferred)
43 * TData TSize Data
44 * </pre>
45 *
46 * @NotThreadSafe
47 * @since 1.11
48 */
49 public class X0016_CertificateIdForCentralDirectory extends PKWareExtraHeader {
50
51 static final ZipShort HEADER_ID = new ZipShort(0x0016);
52
53 private int rcount;
54
55 private HashAlgorithm hashAlg;
56
57 /**
58 * Constructs a new instance.
59 */
60 public X0016_CertificateIdForCentralDirectory() {
61 super(HEADER_ID);
62 }
63
64 /**
65 * Gets hash algorithm.
66 *
67 * @return the hash algorithm
68 */
69 public HashAlgorithm getHashAlgorithm() {
70 return hashAlg;
71 }
72
73 /**
74 * Gets record count.
75 *
76 * @return the record count
77 */
78 public int getRecordCount() {
79 return rcount;
80 }
81
82 @Override
83 public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) throws ZipException {
84 assertMinimalLength(4, length);
85 // TODO: double check we really do not want to call super here
86 this.rcount = ZipShort.getValue(data, offset);
87 this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2));
88 }
89 }