package org.bouncycastle.asn1.cmc.test;


import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cmc.IdentityProofV2;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.util.test.SimpleTest;

public class IdentityProofV2Test
    extends SimpleTest
{
    public static void main(String[] args)
    {
        runTest(new IdentityProofV2Test());
    }

    public String getName()
    {
        return "IdentityProofV2";
    }

    public void performTest()
        throws Exception
    {
        IdentityProofV2 proofV2 = new IdentityProofV2(
            new AlgorithmIdentifier(PKCSObjectIdentifiers.encryptionAlgorithm, ASN1Integer.valueOf(10)),
            new AlgorithmIdentifier(PKCSObjectIdentifiers.bagtypes, ASN1Integer.valueOf(10)),
            "Cats".getBytes()
        );

        byte[] b = proofV2.getEncoded();
        IdentityProofV2 proofV2Res = IdentityProofV2.getInstance(b);

        isEquals("proofAldID", proofV2.getProofAlgID(), proofV2Res.getProofAlgID());
        isEquals("macAlgId", proofV2.getMacAlgId(), proofV2Res.getMacAlgId());
        isTrue("witness",  areEqual(proofV2.getWitness(), proofV2Res.getWitness()));


        try
        {
            IdentityProofV2.getInstance(new DERSequence(new ASN1Encodable[0]));
            fail("Sequence must be length of 3");
        }
        catch (Throwable t)
        {
            isEquals("Exception incorrect", t.getClass(), IllegalArgumentException.class);
        }
    }
}
