added a configurable chunk size to BEROctetString
public class BEROctetString
extends ASN1OctetString
{
- private static final int MAX_LENGTH = 1000;
+ private static final int DEFAULT_LENGTH = 1000;
- private ASN1OctetString[] octs;
+ private final int chunkSize;
+ private final ASN1OctetString[] octs;
/**
* Convert a vector of octet strings into a single byte string
public BEROctetString(
byte[] string)
{
- super(string);
+ this(string, DEFAULT_LENGTH);
}
/**
@@ -74,9 +75,40 @@ public BEROctetString(
public BEROctetString(
ASN1OctetString[] octs)
{
- super(toBytes(octs));
+ this(octs, DEFAULT_LENGTH);
+ }
+
+ /**
+ * Create an OCTET-STRING object from a byte[]
+ * @param string the octets making up the octet string.
+ * @param chunkSize the number of octets stored in each DER encoded component OCTET STRING.
+ */
+ public BEROctetString(
+ byte[] string,
+ int chunkSize)
+ {
+ this(string, null, chunkSize);
+ }
+
+ /**
+ * Multiple {@link ASN1OctetString} data blocks are input,
+ * the result is <i>constructed form</i>.
+ *
+ * @param octs an array of OCTET STRING to construct the BER OCTET STRING from.
+ * @param chunkSize the number of octets stored in each DER encoded component OCTET STRING.
+ */
+ public BEROctetString(
+ ASN1OctetString[] octs,
+ int chunkSize)
+ {
+ this(toBytes(octs), octs, chunkSize);
+ }
+ private BEROctetString(byte[] string, ASN1OctetString[] octs, int chunkSize)
+ {
+ super(string);
this.octs = octs;
+ this.chunkSize = chunkSize;
}
/**
@@ -119,17 +151,17 @@ public Object nextElement()
private Vector generateOcts()
{
Vector vec = new Vector();
- for (int i = 0; i < string.length; i += MAX_LENGTH)
+ for (int i = 0; i < string.length; i += chunkSize)
{
int end;
- if (i + MAX_LENGTH > string.length)
+ if (i + chunkSize > string.length)
{
end = string.length;
}
else
{
- end = i + MAX_LENGTH;
+ end = i + chunkSize;
}
byte[] nStr = new byte[end - i];
