    001package org.apache.commons.ssl.asn1;
    002
    003import java.io.ByteArrayOutputStream;
    004import java.io.IOException;
    005import java.util.Enumeration;
    006
    007/** @deprecated use DERSequence. */
    008public class DERConstructedSequence
    009    extends ASN1Sequence {
    010    public void addObject(
    011        DEREncodable obj) {
    012        super.addObject(obj);
    013    }
    014
    015    public int getSize() {
    016        return size();
    017    }
    018
    019    /*
    020     * A note on the implementation:
    021     * <p>
    022     * As DER requires the constructed, definite-length model to
    023     * be used for structured types, this varies slightly from the
    024     * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
    025     * we also have to specify CONSTRUCTED, and the objects length.
    026     */
    027    void encode(
    028        DEROutputStream out)
    029        throws IOException {
    030        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    031        DEROutputStream dOut = new DEROutputStream(bOut);
    032        Enumeration e = this.getObjects();
    033
    034        while (e.hasMoreElements()) {
    035            Object obj = e.nextElement();
    036
    037            dOut.writeObject(obj);
    038        }
    039
    040        dOut.close();
    041
    042        byte[] bytes = bOut.toByteArray();
    043
    044        out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
    045    }
    046}