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 * http://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 public X0016_CertificateIdForCentralDirectory() { 58 super(HEADER_ID); 59 } 60 61 /** 62 * Gets hash algorithm. 63 * 64 * @return the hash algorithm 65 */ 66 public HashAlgorithm getHashAlgorithm() { 67 return hashAlg; 68 } 69 70 /** 71 * Gets record count. 72 * 73 * @return the record count 74 */ 75 public int getRecordCount() { 76 return rcount; 77 } 78 79 @Override 80 public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) throws ZipException { 81 assertMinimalLength(4, length); 82 // TODO: double check we really do not want to call super here 83 this.rcount = ZipShort.getValue(data, offset); 84 this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2)); 85 } 86 }