View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  
19  package org.apache.geronimo.util.asn1;
20  
21  import java.io.ByteArrayOutputStream;
22  import java.io.IOException;
23  import java.util.Enumeration;
24  
25  /**
26   * @deprecated use DERSequence.
27   */
28  public class DERConstructedSequence
29      extends ASN1Sequence
30  {
31      public void addObject(
32          DEREncodable obj)
33      {
34          super.addObject(obj);
35      }
36  
37      public int getSize()
38      {
39          return size();
40      }
41  
42      /*
43       * A note on the implementation:
44       * <p>
45       * As DER requires the constructed, definite-length model to
46       * be used for structured types, this varies slightly from the
47       * ASN.1 descriptions given. Rather than just outputing SEQUENCE,
48       * we also have to specify CONSTRUCTED, and the objects length.
49       */
50      void encode(
51          DEROutputStream out)
52          throws IOException
53      {
54          ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
55          DEROutputStream         dOut = new DEROutputStream(bOut);
56          Enumeration             e = this.getObjects();
57  
58          while (e.hasMoreElements())
59          {
60              Object    obj = e.nextElement();
61  
62              dOut.writeObject(obj);
63          }
64  
65          dOut.close();
66  
67          byte[]  bytes = bOut.toByteArray();
68  
69          out.writeEncoded(SEQUENCE | CONSTRUCTED, bytes);
70      }
71  }