001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.util.asn1;
019    
020    import java.io.ByteArrayOutputStream;
021    import java.io.IOException;
022    import java.util.Enumeration;
023    
024    /**
025     * @deprecated use DERSequence.
026     */
027    public class DERConstructedSequence
028        extends ASN1Sequence
029    {
030        public void addObject(
031            DEREncodable obj)
032        {
033            super.addObject(obj);
034        }
035    
036        public int getSize()
037        {
038            return size();
039        }
040    
041        /*
042         * A note on the implementation:
043         * <p>
044         * As DER requires the constructed, definite-length model to
045         * be used for structured types, this varies slightly from the
046         * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
047         * we also have to specify CONSTRUCTED, and the objects length.
048         */
049        void encode(
050            DEROutputStream out)
051            throws IOException
052        {
053            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
054            DEROutputStream         dOut = new DEROutputStream(bOut);
055            Enumeration             e = this.getObjects();
056    
057            while (e.hasMoreElements())
058            {
059                Object    obj = e.nextElement();
060    
061                dOut.writeObject(obj);
062            }
063    
064            dOut.close();
065    
066            byte[]  bytes = bOut.toByteArray();
067    
068            out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
069        }
070    }