001 /*
002 * Copyright (c) 2000 - 2006 The Legion Of The Bouncy Castle (http://www.bouncycastle.org)
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this
005 * software and associated documentation files (the "Software"), to deal in the Software
006 * without restriction, including without limitation the rights to use, copy, modify,
007 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
008 * permit persons to whom the Software is furnished to do so, subject to the following
009 * conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in all copies
012 * or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
015 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
016 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
017 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
018 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
019 * DEALINGS IN THE SOFTWARE.
020 *
021 */
022
023 package org.apache.directory.shared.asn1.der;
024
025
026 import java.io.ByteArrayOutputStream;
027 import java.io.IOException;
028 import java.util.Enumeration;
029 import java.util.Vector;
030
031
032 /**
033 * A DER encoded set object
034 */
035 public class DERSet implements DEREncodable
036 {
037 protected Vector<DEREncodable> set = new Vector<DEREncodable>();
038
039
040 public Enumeration<DEREncodable> getObjects()
041 {
042 return set.elements();
043 }
044
045
046 public DEREncodable getObjectAt( int index )
047 {
048 return ( DEREncodable ) set.elementAt( index );
049 }
050
051
052 public int size()
053 {
054 return set.size();
055 }
056
057
058 public void add( DEREncodable obj )
059 {
060 set.addElement( obj );
061 }
062
063
064 public void encode( ASN1OutputStream out ) throws IOException
065 {
066 ByteArrayOutputStream baos = new ByteArrayOutputStream();
067 ASN1OutputStream aos = new ASN1OutputStream( baos );
068
069 Enumeration<DEREncodable> e = getObjects();
070
071 while ( e.hasMoreElements() )
072 {
073 aos.writeObject( e.nextElement() );
074 }
075
076 aos.close();
077
078 byte[] bytes = baos.toByteArray();
079
080 out.writeEncoded( DERObject.SET | DERObject.CONSTRUCTED, bytes );
081 }
082 }