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.Asn1Object.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 is the base class for all other Asn1 types.</summary>
39 public abstract class Asn1Object : System.Runtime.Serialization.ISerializable
42 private Asn1Identifier id;
44 public Asn1Object(Asn1Identifier id)
50 public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
54 /// <summary> Abstract method that must be implemented by each child
55 /// class to encode itself ( an Asn1Object) directly intto
59 /// <param name="out">The output stream onto which the encoded
60 /// Asn1Object will be placed.
62 abstract public void encode(Asn1Encoder enc, System.IO.Stream out_Renamed);
64 /// <summary> Returns the identifier for this Asn1Object as an Asn1Identifier.
65 /// This Asn1Identifier object will include the CLASS, FORM and TAG
66 /// for this Asn1Object.
68 public virtual Asn1Identifier getIdentifier()
73 /// <summary> Sets the identifier for this Asn1Object. This is helpful when
74 /// creating implicit Asn1Tagged types.
77 /// <param name="id">An Asn1Identifier object representing the CLASS,
80 public virtual void setIdentifier(Asn1Identifier id)
86 /// <summary> This method returns a byte array representing the encoded
87 /// Asn1Object. It in turn calls the encode method that is
88 /// defined in Asn1Object but will usually be implemented
89 /// in the child Asn1 classses.
91 [CLSCompliantAttribute(false)]
92 public sbyte[] getEncoding(Asn1Encoder enc)
94 System.IO.MemoryStream out_Renamed = new System.IO.MemoryStream();
97 encode(enc, out_Renamed);
99 catch (System.IO.IOException e)
101 // Should never happen - the current Asn1Object does not have
103 throw new System.SystemException("IOException while encoding to byte array: " + e.ToString());
105 return SupportClass.ToSByteArray(out_Renamed.ToArray());
108 /// <summary> Return a String representation of this Asn1Object.</summary>
109 [CLSCompliantAttribute(false)]
110 public override System.String ToString()
112 System.String[] classTypes = new System.String[]{"[UNIVERSAL ", "[APPLICATION ", "[CONTEXT ", "[PRIVATE "};
114 System.Text.StringBuilder sb = new System.Text.StringBuilder();
115 Asn1Identifier id = getIdentifier(); // could be overridden.
117 sb.Append(classTypes[id.Asn1Class]).Append(id.Tag).Append("] ");
119 return sb.ToString();