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

io.gatling.recorder.internal.bouncycastle.its.ETSIEncryptedData Maven / Gradle / Ivy

There is a newer version: 1.78.1
Show newest version
package io.gatling.recorder.internal.bouncycastle.its;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import io.gatling.recorder.internal.bouncycastle.asn1.ASN1Encodable;
import io.gatling.recorder.internal.bouncycastle.oer.Element;
import io.gatling.recorder.internal.bouncycastle.oer.OEREncoder;
import io.gatling.recorder.internal.bouncycastle.oer.OERInputStream;
import io.gatling.recorder.internal.bouncycastle.oer.its.etsi103097.EtsiTs103097DataEncrypted;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.EncryptedData;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.Ieee1609Dot2Content;
import io.gatling.recorder.internal.bouncycastle.oer.its.ieee1609dot2.RecipientInfo;
import io.gatling.recorder.internal.bouncycastle.oer.its.template.etsi103097.EtsiTs103097Module;
import io.gatling.recorder.internal.bouncycastle.util.CollectionStore;
import io.gatling.recorder.internal.bouncycastle.util.Store;

public class ETSIEncryptedData
{
    private static final Element oerDef = EtsiTs103097Module.EtsiTs103097Data_Encrypted.build();

    private final EncryptedData encryptedData;

    public ETSIEncryptedData(byte[] oerEncoded)
        throws IOException
    {
        this(new ByteArrayInputStream(oerEncoded));
    }

    public ETSIEncryptedData(InputStream str)
        throws IOException
    {
        OERInputStream oerIn;
        if (str instanceof OERInputStream)
        {
            oerIn = (OERInputStream)str;
        }
        else
        {
            oerIn = new OERInputStream(str);
        }
        ASN1Encodable asn1 = oerIn.parse(oerDef);

        Ieee1609Dot2Content content = EtsiTs103097DataEncrypted.getInstance(asn1).getContent();
        if (content.getChoice() != Ieee1609Dot2Content.encryptedData)
        {
            throw new IllegalStateException("EtsiTs103097Data-Encrypted did not have encrypted data content");
        }
        this.encryptedData = EncryptedData.getInstance(content.getIeee1609Dot2Content());
    }

    ETSIEncryptedData(EncryptedData data)
    {
        this.encryptedData = data;
    }

    public byte[] getEncoded()
    {
        return OEREncoder.toByteArray(new EtsiTs103097DataEncrypted(
            Ieee1609Dot2Content
                .encryptedData(encryptedData)
        ), oerDef);
    }

    public EncryptedData getEncryptedData()
    {
        return encryptedData;
    }

    public Store getRecipients()
    {
        List recipients = new ArrayList();
        for (RecipientInfo ri : encryptedData.getRecipients().getRecipientInfos())
        {
            recipients.add(new ETSIRecipientInfo(encryptedData, ri));
        }
        return new CollectionStore(recipients);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy