# Source code

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