001package org.apache.commons.ssl.org.bouncycastle.asn1.esf;
002
003import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1EncodableVector;
004import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Object;
005import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1OctetString;
006import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Primitive;
007import org.apache.commons.ssl.org.bouncycastle.asn1.ASN1Sequence;
008import org.apache.commons.ssl.org.bouncycastle.asn1.DERSequence;
009import org.apache.commons.ssl.org.bouncycastle.asn1.x509.AlgorithmIdentifier;
010
011public class OtherHashAlgAndValue
012    extends ASN1Object
013{
014    private AlgorithmIdentifier hashAlgorithm;
015    private ASN1OctetString     hashValue;
016
017
018    public static OtherHashAlgAndValue getInstance(
019        Object obj)
020    {
021        if (obj instanceof OtherHashAlgAndValue)
022        {
023            return (OtherHashAlgAndValue) obj;
024        }
025        else if (obj != null)
026        {
027            return new OtherHashAlgAndValue(ASN1Sequence.getInstance(obj));
028        }
029
030        return null;
031    }
032
033    private OtherHashAlgAndValue(
034        ASN1Sequence seq)
035    {
036        if (seq.size() != 2)
037        {
038            throw new IllegalArgumentException("Bad sequence size: " + seq.size());
039        }
040
041        hashAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
042        hashValue = ASN1OctetString.getInstance(seq.getObjectAt(1));
043    }
044
045    public OtherHashAlgAndValue(
046        AlgorithmIdentifier hashAlgorithm,
047        ASN1OctetString     hashValue)
048    {
049        this.hashAlgorithm = hashAlgorithm;
050        this.hashValue = hashValue;
051    }
052
053    public AlgorithmIdentifier getHashAlgorithm()
054    {
055        return hashAlgorithm;
056    }
057
058    public ASN1OctetString getHashValue()
059    {
060        return hashValue;
061    }
062
063    /**
064     * <pre>
065     * OtherHashAlgAndValue ::= SEQUENCE {
066     *     hashAlgorithm AlgorithmIdentifier,
067     *     hashValue OtherHashValue }
068     *
069     * OtherHashValue ::= OCTET STRING
070     * </pre>
071     */
072    public ASN1Primitive toASN1Primitive()
073    {
074        ASN1EncodableVector v = new ASN1EncodableVector();
075
076        v.add(hashAlgorithm);
077        v.add(hashValue);
078
079        return new DERSequence(v);
080    }
081}