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.crypto.asn1; 019 020 import java.io.ByteArrayOutputStream; 021 import java.io.IOException; 022 import java.util.Enumeration; 023 024 /** 025 * 026 * @deprecated use DERSet 027 */ 028 public class DERConstructedSet 029 extends ASN1Set 030 { 031 public DERConstructedSet() 032 { 033 } 034 035 /** 036 * @param obj - a single object that makes up the set. 037 */ 038 public DERConstructedSet( 039 DEREncodable obj) 040 { 041 this.addObject(obj); 042 } 043 044 /** 045 * @param v - a vector of objects making up the set. 046 */ 047 public DERConstructedSet( 048 DEREncodableVector v) 049 { 050 for (int i = 0; i != v.size(); i++) 051 { 052 this.addObject(v.get(i)); 053 } 054 } 055 056 public void addObject( 057 DEREncodable obj) 058 { 059 super.addObject(obj); 060 } 061 062 public int getSize() 063 { 064 return size(); 065 } 066 067 /* 068 * A note on the implementation: 069 * <p> 070 * As DER requires the constructed, definite-length model to 071 * be used for structured types, this varies slightly from the 072 * ASN.1 descriptions given. Rather than just outputing SET, 073 * we also have to specify CONSTRUCTED, and the objects length. 074 */ 075 void encode( 076 DEROutputStream out) 077 throws IOException 078 { 079 ByteArrayOutputStream bOut = new ByteArrayOutputStream(); 080 DEROutputStream dOut = new DEROutputStream(bOut); 081 Enumeration e = this.getObjects(); 082 083 while (e.hasMoreElements()) 084 { 085 Object obj = e.nextElement(); 086 087 dOut.writeObject(obj); 088 } 089 090 dOut.close(); 091 092 byte[] bytes = bOut.toByteArray(); 093 094 out.writeEncoded(SET | CONSTRUCTED, bytes); 095 } 096 }