Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Asn1Structured.cs « Novell.Directory.Ldap.Asn1 « Novell.Directory.Ldap « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f6dadd4d0504b062ffe6400ebd9050e5072ef174 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/******************************************************************************
* The MIT License
* Copyright (c) 2003 Novell Inc.  www.novell.com
* 
* Permission is hereby granted, free of charge, to any person obtaining  a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including  without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
* copies of the Software, and to  permit persons to whom the Software is 
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in 
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*******************************************************************************/
//
// Novell.Directory.Ldap.Asn1.Asn1Structured.cs
//
// Author:
//   Sunil Kumar (Sunilk@novell.com)
//
// (C) 2003 Novell, Inc (http://www.novell.com)
//

using System;

namespace Novell.Directory.Ldap.Asn1
{
	
	/// <summary> This class serves as the base type for all ASN.1
	/// structured types.
	/// </summary>
	[CLSCompliantAttribute(true)]
	public abstract class Asn1Structured:Asn1Object
	{
		private Asn1Object[] content;
		
		private int contentIndex = 0;
		
		/*
		* Create a an Asn1 structured type with default size of 10
		*
		* @param the Asn1Identifier containing the tag for this structured type
		*/
		protected internal Asn1Structured(Asn1Identifier id):this(id, 10)
		{
			return ;
		}
		
		/*
		* Create a an Asn1 structured type with the designated size
		*
		* @param id the Asn1Identifier containing the tag for this structured type
		*
		* @param size the size to allocate
		*/
		protected internal Asn1Structured(Asn1Identifier id, int size):base(id)
		{
			content = new Asn1Object[size];
			return ;
		}
		
		/*
		* Create a an Asn1 structured type with default size of 10
		*
		* @param id the Asn1Identifier containing the tag for this structured type
		*
		* @param content an array containing the content
		*
		* @param size the number of items of content in the array
		*/
		protected internal Asn1Structured(Asn1Identifier id, Asn1Object[] newContent, int size):base(id)
		{
			content = newContent;
			contentIndex = size;
			return ;
		}
		
		/// <summary> Encodes the contents of this Asn1Structured directly to an output
		/// stream.
		/// </summary>
		public override void  encode(Asn1Encoder enc, System.IO.Stream out_Renamed)
		{
			enc.encode(this, out_Renamed);
			return ;
		}
		
		/// <summary> Decode an Asn1Structured type from an InputStream.</summary>
		[CLSCompliantAttribute(false)]
		protected internal void  decodeStructured(Asn1Decoder dec, System.IO.Stream in_Renamed, int len)
		{
			int[] componentLen = new int[1]; // collects length of component
			
			while (len > 0)
			{
				add(dec.decode(in_Renamed, componentLen));
				len -= componentLen[0];
			}
			return ;
		}
		
		/// <summary> Returns an array containing the individual ASN.1 elements
		/// of this Asn1Structed object.
		/// 
		/// </summary>
		/// <returns> an array of Asn1Objects
		/// </returns>
		public Asn1Object[] toArray()
		{
			Asn1Object[] cloneArray = new Asn1Object[contentIndex];
			Array.Copy((System.Array) content, 0, (System.Array) cloneArray, 0, contentIndex);
			return cloneArray;
		}
		
		/// <summary> Adds a new Asn1Object to the end of this Asn1Structured
		/// object.
		/// 
		/// </summary>
		/// <param name="value">The Asn1Object to add to this Asn1Structured
		/// object.
		/// </param>
		public void  add(Asn1Object value_Renamed)
		{
			if (contentIndex == content.Length)
			{
				// Array too small, need to expand it, double length
				int newSize = contentIndex + contentIndex;
				Asn1Object[] newArray = new Asn1Object[newSize];
				Array.Copy((System.Array) content, 0, (System.Array) newArray, 0, contentIndex);
				content = newArray;
			}
			content[contentIndex++] = value_Renamed;
			return ;
		}
		
		/// <summary> Replaces the Asn1Object in the specified index position of
		/// this Asn1Structured object.
		/// 
		/// </summary>
		/// <param name="index">The index into the Asn1Structured object where
		/// this new ANS1Object will be placed.
		/// 
		/// </param>
		/// <param name="value">The Asn1Object to set in this Asn1Structured
		/// object.
		/// </param>
		public void  set_Renamed(int index, Asn1Object value_Renamed)
		{
			if ((index >= contentIndex) || (index < 0))
			{
				throw new System.IndexOutOfRangeException("Asn1Structured: get: index " + index + ", size " + contentIndex);
			}
			content[index] = value_Renamed;
			return ;
		}
		
		/// <summary> Gets a specific Asn1Object in this structred object.
		/// 
		/// </summary>
		/// <param name="index">The index of the Asn1Object to get from
		/// this Asn1Structured object.
		/// </param>
		public Asn1Object get_Renamed(int index)
		{
			if ((index >= contentIndex) || (index < 0))
			{
				throw new System.IndexOutOfRangeException("Asn1Structured: set: index " + index + ", size " + contentIndex);
			}
			return content[index];
		}
		
		/// <summary> Returns the number of Asn1Obejcts that have been encoded
		/// into this Asn1Structured class.
		/// </summary>
		public int size()
		{
			return contentIndex;
		}
		
		/// <summary> Creates a String representation of this Asn1Structured.
		/// object.
		/// 
		/// </summary>
		/// <param name="type">the Type to put in the String representing this structured object
		/// 
		/// </param>
		/// <returns> the String representation of this object.
		/// </returns>
		[CLSCompliantAttribute(false)]
		public virtual System.String toString(System.String type)
		{
			System.Text.StringBuilder sb = new System.Text.StringBuilder();
			
			sb.Append(type);
			
			for (int i = 0; i < contentIndex; i++)
			{
				sb.Append(content[i]);
				if (i != contentIndex - 1)
					sb.Append(", ");
			}
			sb.Append(" }");
			
			return base.ToString() + sb.ToString();
		}
	}
}