    001package org.apache.commons.ssl.asn1;
    002
    003import java.io.ByteArrayOutputStream;
    004import java.io.IOException;
    005import java.util.Enumeration;
    006
    007/** @deprecated use DERSet */
    008public class DERConstructedSet
    009    extends ASN1Set {
    010    public DERConstructedSet() {
    011    }
    012
    013    /** @param obj - a single object that makes up the set. */
    014    public DERConstructedSet(
    015        DEREncodable obj) {
    016        this.addObject(obj);
    017    }
    018
    019    /** @param v - a vector of objects making up the set. */
    020    public DERConstructedSet(
    021        DEREncodableVector v) {
    022        for (int i = 0; i != v.size(); i++) {
    023            this.addObject(v.get(i));
    024        }
    025    }
    026
    027    public void addObject(
    028        DEREncodable obj) {
    029        super.addObject(obj);
    030    }
    031
    032    public int getSize() {
    033        return size();
    034    }
    035
    036    /*
    037     * A note on the implementation:
    038     * <p>
    039     * As DER requires the constructed, definite-length model to
    040     * be used for structured types, this varies slightly from the
    041     * ASN.1 descriptions given. Rather than just outputing SET,
    042     * we also have to specify CONSTRUCTED, and the objects length.
    043     */
    044    void encode(
    045        DEROutputStream out)
    046        throws IOException {
    047        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    048        DEROutputStream dOut = new DEROutputStream(bOut);
    049        Enumeration e = this.getObjects();
    050
    051        while (e.hasMoreElements()) {
    052            Object obj = e.nextElement();
    053
    054            dOut.writeObject(obj);
    055        }
    056
    057        dOut.close();
    058
    059        byte[] bytes = bOut.toByteArray();
    060
    061        out.writeEncoded(SET | CONSTRUCTED, bytes);
    062    }
    063}