001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.commons.compress.archivers.zip; 020 021/** 022 * X.509 Certificate ID and Signature for central directory (0x0016). 023 * 024 * <p>This field contains the information about which certificate in the PKCS#7 025 * store was used to sign the central directory structure. When the Central 026 * Directory Encryption feature is enabled for a ZIP file, this record will 027 * appear in the Archive Extra Data Record, otherwise it will appear in the 028 * first central directory record.</p> 029 * 030 * <p>Note: all fields stored in Intel low-byte/high-byte order.</p> 031 * 032 * <pre> 033 * Value Size Description 034 * ----- ---- ----------- 035 * (CDID) 0x0016 2 bytes Tag for this "extra" block type 036 * TSize 2 bytes Size of data that follows 037 * RCount 4 bytes Number of recipients. (inferred) 038 * HashAlg 2 bytes Hash algorithm identifier. (inferred) 039 * TData TSize Data 040 * </pre> 041 * 042 * @NotThreadSafe 043 * @since 1.11 044 */ 045public class X0016_CertificateIdForCentralDirectory extends PKWareExtraHeader implements ZipExtraField { 046 private static final long serialVersionUID = 1L; 047 048 public X0016_CertificateIdForCentralDirectory() { 049 super(new ZipShort(0x0016)); 050 } 051 052 private int rcount; 053 private HashAlgorithm hashAlg; 054 055 /** 056 * Get record count. 057 * @return the record count 058 */ 059 public int getRecordCount() { 060 return rcount; 061 } 062 063 /** 064 * Get hash algorithm. 065 * @return the hash algorithm 066 */ 067 public HashAlgorithm getHashAlgorithm() { 068 return hashAlg; 069 } 070 071 @Override 072 public void parseFromCentralDirectoryData(byte[] data, int offset, int length) { 073 this.rcount = ZipShort.getValue(data, offset); 074 this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2)); 075 } 076}