org.bouncycastle.oer.its.ieee1609dot2.PKRecipientInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcutil-fips Show documentation
Show all versions of bcutil-fips Show documentation
The Bouncy Castle Java APIs for ASN.1 extension and utility APIs used to support bcpkix and bctls with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
The newest version!
package org.bouncycastle.oer.its.ieee1609dot2;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.oer.its.ItsUtils;
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.HashedId;
import org.bouncycastle.oer.its.ieee1609dot2.basetypes.HashedId8;
/**
*
* PKRecipientInfo ::= SEQUENCE {
* recipientId HashedId8,
* encKey EncryptedDataEncryptionKey
* }
*
*/
public class PKRecipientInfo
extends ASN1Object
{
private final HashedId8 recipientId;
private final EncryptedDataEncryptionKey encKey;
public PKRecipientInfo(HashedId8 recipientId, EncryptedDataEncryptionKey encKey)
{
this.recipientId = recipientId;
this.encKey = encKey;
}
private PKRecipientInfo(ASN1Sequence sequence)
{
if (sequence.size() != 2)
{
throw new IllegalArgumentException("expected sequence size of 2");
}
recipientId = HashedId8.getInstance(sequence.getObjectAt(0));
encKey = EncryptedDataEncryptionKey.getInstance(sequence.getObjectAt(1));
}
public static PKRecipientInfo getInstance(Object object)
{
if (object instanceof PKRecipientInfo)
{
return (PKRecipientInfo)object;
}
if (object != null)
{
return new PKRecipientInfo(ASN1Sequence.getInstance(object));
}
return null;
}
public HashedId getRecipientId()
{
return recipientId;
}
public EncryptedDataEncryptionKey getEncKey()
{
return encKey;
}
public ASN1Primitive toASN1Primitive()
{
return ItsUtils.toSequence(recipientId, encKey);
}
public static Builder builder()
{
return new Builder();
}
public static class Builder
{
private HashedId8 recipientId;
private EncryptedDataEncryptionKey encKey;
public Builder setRecipientId(HashedId8 recipientId)
{
this.recipientId = recipientId;
return this;
}
public Builder setEncKey(EncryptedDataEncryptionKey encKey)
{
this.encKey = encKey;
return this;
}
public PKRecipientInfo createPKRecipientInfo()
{
return new PKRecipientInfo(recipientId, encKey);
}
}
}