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
021import java.util.zip.ZipException;
022
023/**
024 * X.509 Certificate ID and Signature for individual file (0x0015).
025 *
026 * <p>This field contains the information about which certificate in the PKCS#7
027 * store was used to sign a particular file. It also contains the signature
028 * data. This field can appear multiple times, but can only appear once per
029 * certificate.</p>
030 *
031 * <p>Note: all fields stored in Intel low-byte/high-byte order.</p>
032 *
033 * <pre>
034 *         Value     Size     Description
035 *         -----     ----     -----------
036 * (CID)   0x0015    2 bytes  Tag for this "extra" block type
037 *         TSize     2 bytes  Size of data that follows
038 *         RCount    4 bytes  Number of recipients. (inferred)
039 *         HashAlg   2 bytes  Hash algorithm identifier. (inferred)
040 *         TData     TSize    Signature Data
041 * </pre>
042 *
043 * @NotThreadSafe
044 * @since 1.11
045 */
046public class X0015_CertificateIdForFile extends PKWareExtraHeader {
047
048    private int rcount;
049
050    private HashAlgorithm hashAlg;
051
052    public X0015_CertificateIdForFile() {
053        super(new ZipShort(0x0015));
054    }
055
056    /**
057     * Gets hash algorithm.
058     * @return the hash algorithm
059     */
060    public HashAlgorithm getHashAlgorithm() {
061        return hashAlg;
062    }
063
064    /**
065     * Gets record count.
066     * @return the record count
067     */
068    public int getRecordCount() {
069        return rcount;
070    }
071
072    @Override
073    public void parseFromCentralDirectoryData(final byte[] data, final int offset, final int length)
074        throws ZipException {
075        assertMinimalLength(4, length);
076        super.parseFromCentralDirectoryData(data, offset, length);
077        this.rcount = ZipShort.getValue(data, offset);
078        this.hashAlg = HashAlgorithm.getAlgorithmByCode(ZipShort.getValue(data, offset + 2));
079    }
080}