org.bouncycastle.its.asn1.SequenceOfOctetString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bcprov-jdk15to18 Show documentation
Show all versions of bcprov-jdk15to18 Show documentation
The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
package org.bouncycastle.its.asn1;
import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1Object;
import org.bouncycastle.asn1.ASN1OctetString;
import org.bouncycastle.asn1.ASN1Primitive;
import org.bouncycastle.asn1.ASN1Sequence;
import org.bouncycastle.asn1.DEROctetString;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.util.Arrays;
/**
*
* SequenceOfOctetString ::= SEQUENCE (SIZE(0..MAX)) OF OCTET STRING (SIZE(0..MAX))
*
*/
public class SequenceOfOctetString
extends ASN1Object
{
private byte[][] octetStrings;
private SequenceOfOctetString(ASN1Sequence seq)
{
this.octetStrings = toByteArrays(seq);
}
public static SequenceOfOctetString getInstance(Object o)
{
if (o instanceof SequenceOfOctetString)
{
return (SequenceOfOctetString)o;
}
else if (o != null)
{
return new SequenceOfOctetString(ASN1Sequence.getInstance(o));
}
return null;
}
public int size()
{
return octetStrings.length;
}
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector();
for (int i = 0; i != octetStrings.length; i++)
{
v.add(new DEROctetString(Arrays.clone(octetStrings[i])));
}
return new DERSequence(v);
}
static byte[][] toByteArrays(ASN1Sequence seq)
{
byte[][] octetStrings = new byte[seq.size()][];
for (int i = 0; i != seq.size(); i++)
{
octetStrings[i] = ASN1OctetString.getInstance(seq.getObjectAt(i)).getOctets();
}
return octetStrings;
}
}