| 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 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 | /** |
| 57 | * Constructs a new instance. |
| 58 | */ |
| 59 | public X0015_CertificateIdForFile() { |
| 60 | super(HEADER_ID); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Gets hash algorithm. |
| 65 | * |
| 66 | * @return the hash algorithm |
| 67 | */ |
| 68 | public HashAlgorithm getHashAlgorithm() { |
| 69 | return hashAlg; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Gets record count. |
| 74 | * |
| 75 | * @return the record count |
| 76 | */ |
| 77 | public int getRecordCount() { |
| 78 | return rcount; |
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length) throws ZipException { |
| 83 | assertMinimalLength(4, length); |
| 84 | super.parseFromCentralDirectoryData(data, offset, length); |
| 85 | this.rcount = ZipShort.getValue(data, offset); |
| 86 | this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2)); |
| 87 | } |
| 88 | } |