All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bouncycastle.tsp.ers.ERSCachingData Maven / Gradle / Ivy

Go to download

The Bouncy Castle Java APIs for CMS, PKCS, EAC, TSP, CMP, CRMF, OCSP, and certificate generation. This jar contains APIs for JDK 1.5 and up. The APIs can be used in conjunction with a JCE/JCA provider such as the one provided with the Bouncy Castle Cryptography APIs.

The newest version!
package org.bouncycastle.tsp.ers;

import java.util.HashMap;
import java.util.Map;

import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.operator.DigestCalculator;

/**
 * An ERSData object that caches hash calculations.
 */
public abstract class ERSCachingData
    implements ERSData
{
    private Map preCalcs = new HashMap();

    /**
     * Generates a hash for the whole DataGroup.
     *
     * @param digestCalculator the {@link DigestCalculator} to use for computing the hash
     * @return a hash that is representative of the whole DataGroup
     */
    public byte[] getHash(DigestCalculator digestCalculator)
    {
        AlgorithmIdentifier digAlgID = digestCalculator.getAlgorithmIdentifier();
        if (preCalcs.containsKey(digAlgID))
        {
            return (byte[])preCalcs.get(digAlgID);
        }

        byte[] hash = calculateHash(digestCalculator);

        preCalcs.put(digAlgID, hash);

        return hash;
    }

    protected abstract byte[] calculateHash(DigestCalculator digestCalculator);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy