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 individual file (0x0015). 25 * 26 * <p> 27 * This field contains the information about which certificate in the PKCS#7 store was used to sign a particular file. It also contains the signature data. This 28 * field can appear multiple times, but can only appear once per certificate. 29 * </p> 30 * 31 * <p> 32 * Note: all fields stored in Intel low-byte/high-byte order. 33 * </p> 34 * 35 * <pre> 36 * Value Size Description 37 * ----- ---- ----------- 38 * (CID) 0x0015 2 bytes Tag for this "extra" block type 39 * TSize 2 bytes Size of data that follows 40 * RCount 4 bytes Number of recipients. (inferred) 41 * HashAlg 2 bytes Hash algorithm identifier. (inferred) 42 * TData TSize Signature Data 43 * </pre> 44 * 45 * @NotThreadSafe 46 * @since 1.11 47 */ 48 public class X0015_CertificateIdForFile extends PKWareExtraHeader { 49 50 static final ZipShort HEADER_ID = new ZipShort(0x0015); 51 52 private int rcount; 53 54 private HashAlgorithm hashAlg; 55 56 public X0015_CertificateIdForFile() { 57 super(HEADER_ID); 58 } 59 60 /** 61 * Gets hash algorithm. 62 * 63 * @return the hash algorithm 64 */ 65 public HashAlgorithm getHashAlgorithm() { 66 return hashAlg; 67 } 68 69 /** 70 * Gets record count. 71 * 72 * @return the record count 73 */ 74 public int getRecordCount() { 75 return rcount; 76 } 77 78 @Override 79 public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) throws ZipException { 80 assertMinimalLength(4, length); 81 super.parseFromCentralDirectoryData(data, offset, length); 82 this.rcount = ZipShort.getValue(data, offset); 83 this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2)); 84 } 85 }