1 package org.bouncycastle.asn1;
6 public class BERConstructedOctetString
10 * convert a vector of octet strings into a single byte string
12 static private byte[] toBytes(
15 ByteArrayOutputStream bOut = new ByteArrayOutputStream();
17 for (int i = 0; i != octs.size(); i++)
19 DEROctetString o = (DEROctetString)octs.elementAt(i);
23 bOut.write(o.getOctets());
27 throw new RuntimeException("exception converting octets " + e.toString());
31 return bOut.toByteArray();
37 * @param string the octets making up the octet string.
39 public BERConstructedOctetString(
45 public BERConstructedOctetString(
53 public BERConstructedOctetString(
59 public BERConstructedOctetString(
62 super(obj.getDERObject());
65 public byte[] getOctets()
71 * return the DER octets that make up this string.
73 public Enumeration getObjects()
77 octs = generateOcts();
80 return octs.elements();
83 private Vector generateOcts()
87 Vector vec = new Vector();
89 while ((end + 1) < string.length)
91 if (string[end] == 0 && string[end + 1] == 0)
93 byte[] nStr = new byte[end - start + 1];
95 for (int i = 0; i != nStr.length; i++)
97 nStr[i] = string[start + i];
100 vec.addElement(new DEROctetString(nStr));
106 byte[] nStr = new byte[string.length - start];
107 for (int i = 0; i != nStr.length; i++)
109 nStr[i] = string[start + i];
112 vec.addElement(new DEROctetString(nStr));
121 if (out instanceof ASN1OutputStream || out instanceof BEROutputStream)
123 out.write(CONSTRUCTED | OCTET_STRING);
129 octs = generateOcts();
132 for (int i = 0; i != octs.size(); i++)
134 out.writeObject(octs.elementAt(i));