(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Asn1 / Asn1Structured.cs
blobf6dadd4d0504b062ffe6400ebd9050e5072ef174
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc. www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
24 // Novell.Directory.Ldap.Asn1.Asn1Structured.cs
26 // Author:
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
32 using System;
34 namespace Novell.Directory.Ldap.Asn1
37 /// <summary> This class serves as the base type for all ASN.1
38 /// structured types.
39 /// </summary>
40 [CLSCompliantAttribute(true)]
41 public abstract class Asn1Structured:Asn1Object
43 private Asn1Object[] content;
45 private int contentIndex = 0;
48 * Create a an Asn1 structured type with default size of 10
50 * @param the Asn1Identifier containing the tag for this structured type
52 protected internal Asn1Structured(Asn1Identifier id):this(id, 10)
54 return ;
58 * Create a an Asn1 structured type with the designated size
60 * @param id the Asn1Identifier containing the tag for this structured type
62 * @param size the size to allocate
64 protected internal Asn1Structured(Asn1Identifier id, int size):base(id)
66 content = new Asn1Object[size];
67 return ;
71 * Create a an Asn1 structured type with default size of 10
73 * @param id the Asn1Identifier containing the tag for this structured type
75 * @param content an array containing the content
77 * @param size the number of items of content in the array
79 protected internal Asn1Structured(Asn1Identifier id, Asn1Object[] newContent, int size):base(id)
81 content = newContent;
82 contentIndex = size;
83 return ;
86 /// <summary> Encodes the contents of this Asn1Structured directly to an output
87 /// stream.
88 /// </summary>
89 public override void encode(Asn1Encoder enc, System.IO.Stream out_Renamed)
91 enc.encode(this, out_Renamed);
92 return ;
95 /// <summary> Decode an Asn1Structured type from an InputStream.</summary>
96 [CLSCompliantAttribute(false)]
97 protected internal void decodeStructured(Asn1Decoder dec, System.IO.Stream in_Renamed, int len)
99 int[] componentLen = new int[1]; // collects length of component
101 while (len > 0)
103 add(dec.decode(in_Renamed, componentLen));
104 len -= componentLen[0];
106 return ;
109 /// <summary> Returns an array containing the individual ASN.1 elements
110 /// of this Asn1Structed object.
111 ///
112 /// </summary>
113 /// <returns> an array of Asn1Objects
114 /// </returns>
115 public Asn1Object[] toArray()
117 Asn1Object[] cloneArray = new Asn1Object[contentIndex];
118 Array.Copy((System.Array) content, 0, (System.Array) cloneArray, 0, contentIndex);
119 return cloneArray;
122 /// <summary> Adds a new Asn1Object to the end of this Asn1Structured
123 /// object.
124 ///
125 /// </summary>
126 /// <param name="value">The Asn1Object to add to this Asn1Structured
127 /// object.
128 /// </param>
129 public void add(Asn1Object value_Renamed)
131 if (contentIndex == content.Length)
133 // Array too small, need to expand it, double length
134 int newSize = contentIndex + contentIndex;
135 Asn1Object[] newArray = new Asn1Object[newSize];
136 Array.Copy((System.Array) content, 0, (System.Array) newArray, 0, contentIndex);
137 content = newArray;
139 content[contentIndex++] = value_Renamed;
140 return ;
143 /// <summary> Replaces the Asn1Object in the specified index position of
144 /// this Asn1Structured object.
145 ///
146 /// </summary>
147 /// <param name="index">The index into the Asn1Structured object where
148 /// this new ANS1Object will be placed.
149 ///
150 /// </param>
151 /// <param name="value">The Asn1Object to set in this Asn1Structured
152 /// object.
153 /// </param>
154 public void set_Renamed(int index, Asn1Object value_Renamed)
156 if ((index >= contentIndex) || (index < 0))
158 throw new System.IndexOutOfRangeException("Asn1Structured: get: index " + index + ", size " + contentIndex);
160 content[index] = value_Renamed;
161 return ;
164 /// <summary> Gets a specific Asn1Object in this structred object.
165 ///
166 /// </summary>
167 /// <param name="index">The index of the Asn1Object to get from
168 /// this Asn1Structured object.
169 /// </param>
170 public Asn1Object get_Renamed(int index)
172 if ((index >= contentIndex) || (index < 0))
174 throw new System.IndexOutOfRangeException("Asn1Structured: set: index " + index + ", size " + contentIndex);
176 return content[index];
179 /// <summary> Returns the number of Asn1Obejcts that have been encoded
180 /// into this Asn1Structured class.
181 /// </summary>
182 public int size()
184 return contentIndex;
187 /// <summary> Creates a String representation of this Asn1Structured.
188 /// object.
189 ///
190 /// </summary>
191 /// <param name="type">the Type to put in the String representing this structured object
192 ///
193 /// </param>
194 /// <returns> the String representation of this object.
195 /// </returns>
196 [CLSCompliantAttribute(false)]
197 public virtual System.String toString(System.String type)
199 System.Text.StringBuilder sb = new System.Text.StringBuilder();
201 sb.Append(type);
203 for (int i = 0; i < contentIndex; i++)
205 sb.Append(content[i]);
206 if (i != contentIndex - 1)
207 sb.Append(", ");
209 sb.Append(" }");
211 return base.ToString() + sb.ToString();