[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Asn1 / Asn1Length.cs
blob9f0e27d5e90bf0a42f9172907f234d8560c72349
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.Asn1Length.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 provides a means to manipulate ASN.1 Length's. It will
38 /// be used by Asn1Encoder's and Asn1Decoder's by composition.
39 /// </summary>
40 public class Asn1Length
42 /// <summary> Returns the length of this Asn1Length.</summary>
43 virtual public int Length
45 get
47 return length;
51 /// <summary> Returns the encoded length of this Asn1Length.</summary>
52 virtual public int EncodedLength
54 get
56 return encodedLength;
61 /* Private variables
64 private int length;
65 private int encodedLength;
67 /* Constructors for Asn1Length
70 /// <summary> Constructs an empty Asn1Length. Values are added by calling reset</summary>
71 public Asn1Length()
74 /// <summary> Constructs an Asn1Length</summary>
75 public Asn1Length(int length)
77 this.length = length;
80 /// <summary> Constructs an Asn1Length object by decoding data from an
81 /// input stream.
82 ///
83 /// </summary>
84 /// <param name="in">A byte stream that contains the encoded ASN.1
85 ///
86 /// </param>
87 public Asn1Length(System.IO.Stream in_Renamed)
89 int r = in_Renamed.ReadByte();
90 encodedLength++;
91 if (r == 0x80)
92 length = - 1;
93 else if (r < 0x80)
94 length = r;
95 else
97 length = 0;
98 for (r = r & 0x7F; r > 0; r--)
100 int part = in_Renamed.ReadByte();
101 encodedLength++;
102 if (part < 0)
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
110 /// input stream.
111 ///
112 /// Note: this was added for optimization of Asn1.LBERdecoder.decode()
113 ///
114 /// </summary>
115 /// <param name="in">A byte stream that contains the encoded ASN.1
116 ///
117 /// </param>
118 public void reset(System.IO.Stream in_Renamed)
120 encodedLength = 0;
121 int r = in_Renamed.ReadByte();
122 encodedLength++;
123 if (r == 0x80)
124 length = - 1;
125 else if (r < 0x80)
126 length = r;
127 else
129 length = 0;
130 for (r = r & 0x7F; r > 0; r--)
132 int part = in_Renamed.ReadByte();
133 encodedLength++;
134 if (part < 0)
135 throw new System.IO.EndOfStreamException("BERDecoder: decode: EOF in Asn1Length");
136 length = (length << 8) + part;