1 /******************************************************************************
3 * Copyright (c) 2003 Novell Inc. www.novell.com
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
22 *******************************************************************************/
24 // Novell.Directory.Ldap.Asn1.Asn1Length.cs
27 // Sunil Kumar (Sunilk@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
34 namespace Novell
.Directory
.Ldap
.Asn1
37 /// <summary> This class provides a means to manipulate ASN.1 Length's. It will
38 /// be used by Asn1Encoder's and Asn1Decoder's by composition.
40 public class Asn1Length
42 /// <summary> Returns the length of this Asn1Length.</summary>
43 virtual public int Length
51 /// <summary> Returns the encoded length of this Asn1Length.</summary>
52 virtual public int EncodedLength
65 private int encodedLength
;
67 /* Constructors for Asn1Length
70 /// <summary> Constructs an empty Asn1Length. Values are added by calling reset</summary>
74 /// <summary> Constructs an Asn1Length</summary>
75 public Asn1Length(int length
)
80 /// <summary> Constructs an Asn1Length object by decoding data from an
84 /// <param name="in">A byte stream that contains the encoded ASN.1
87 public Asn1Length(System
.IO
.Stream in_Renamed
)
89 int r
= in_Renamed
.ReadByte();
98 for (r
= r
& 0x7F; r
> 0; r
--)
100 int part
= in_Renamed
.ReadByte();
103 throw new System
.IO
.EndOfStreamException("BERDecoder: decode: EOF in Asn1Length");
104 length
= (length
<< 8) + part
;
109 /// <summary> Resets an Asn1Length object by decoding data from an
112 /// Note: this was added for optimization of Asn1.LBERdecoder.decode()
115 /// <param name="in">A byte stream that contains the encoded ASN.1
118 public void reset(System
.IO
.Stream in_Renamed
)
121 int r
= in_Renamed
.ReadByte();
130 for (r
= r
& 0x7F; r
> 0; r
--)
132 int part
= in_Renamed
.ReadByte();
135 throw new System
.IO
.EndOfStreamException("BERDecoder: decode: EOF in Asn1Length");
136 length
= (length
<< 8) + part
;