using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using Mono.Xml;
namespace System.Security
{
/// Represents the XML object model for encoding security objects. This class cannot be inherited.
// Token: 0x020005CD RID: 1485
[ComVisible(true)]
[Serializable]
public sealed class SecurityElement
{
/// Initializes a new instance of the class with the specified tag.
/// The tag name of an XML element.
/// The parameter is null.
/// The parameter is invalid in XML.
// Token: 0x06003625 RID: 13861 RVA: 0x000B91E8 File Offset: 0x000B73E8
public SecurityElement(string tag)
: this(tag, null)
{
}
/// Initializes a new instance of the class with the specified tag and text.
/// The tag name of the XML element.
/// The text content within the element.
/// The parameter is null.
/// The parameter or parameter is invalid in XML.
// Token: 0x06003626 RID: 13862 RVA: 0x000B91F4 File Offset: 0x000B73F4
public SecurityElement(string tag, string text)
{
if (tag == null)
{
throw new ArgumentNullException("tag");
}
if (!SecurityElement.IsValidTag(tag))
{
throw new ArgumentException(Locale.GetText("Invalid XML string") + ": " + tag);
}
this.tag = tag;
this.Text = text;
}
// Token: 0x06003627 RID: 13863 RVA: 0x000B924C File Offset: 0x000B744C
internal SecurityElement(SecurityElement se)
{
this.Tag = se.Tag;
this.Text = se.Text;
if (se.attributes != null)
{
foreach (object obj in se.attributes)
{
SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
this.AddAttribute(securityAttribute.Name, securityAttribute.Value);
}
}
if (se.children != null)
{
foreach (object obj2 in se.children)
{
SecurityElement securityElement = (SecurityElement)obj2;
this.AddChild(securityElement);
}
}
}
/// Gets or sets the attributes of an XML element as name/value pairs.
/// The object for the attribute values of the XML element.
/// The name or value of the object is invalid.
// Token: 0x17000A95 RID: 2709
// (get) Token: 0x06003629 RID: 13865 RVA: 0x000B93E8 File Offset: 0x000B75E8
// (set) Token: 0x0600362A RID: 13866 RVA: 0x000B9484 File Offset: 0x000B7684
public Hashtable Attributes
{
get
{
if (this.attributes == null)
{
return null;
}
Hashtable hashtable = new Hashtable(this.attributes.Count);
foreach (object obj in this.attributes)
{
SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
hashtable.Add(securityAttribute.Name, securityAttribute.Value);
}
return hashtable;
}
set
{
if (value == null || value.Count == 0)
{
this.attributes.Clear();
return;
}
if (this.attributes == null)
{
this.attributes = new ArrayList();
}
else
{
this.attributes.Clear();
}
IDictionaryEnumerator enumerator = value.GetEnumerator();
while (enumerator.MoveNext())
{
this.attributes.Add(new SecurityElement.SecurityAttribute((string)enumerator.Key, (string)enumerator.Value));
}
}
}
/// Gets or sets the array of child elements of the XML element.
/// The ordered child elements of the XML element as security elements.
/// A child of the XML parent node is null.
// Token: 0x17000A96 RID: 2710
// (get) Token: 0x0600362B RID: 13867 RVA: 0x000B9514 File Offset: 0x000B7714
// (set) Token: 0x0600362C RID: 13868 RVA: 0x000B951C File Offset: 0x000B771C
public ArrayList Children
{
get
{
return this.children;
}
set
{
if (value != null)
{
using (IEnumerator enumerator = value.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (enumerator.Current == null)
{
throw new ArgumentNullException();
}
}
}
}
this.children = value;
}
}
/// Gets or sets the tag name of an XML element.
/// The tag name of an XML element.
/// The tag is null.
/// The tag is not valid in XML.
// Token: 0x17000A97 RID: 2711
// (get) Token: 0x0600362D RID: 13869 RVA: 0x000B9594 File Offset: 0x000B7794
// (set) Token: 0x0600362E RID: 13870 RVA: 0x000B959C File Offset: 0x000B779C
public string Tag
{
get
{
return this.tag;
}
set
{
if (value == null)
{
throw new ArgumentNullException("Tag");
}
if (!SecurityElement.IsValidTag(value))
{
throw new ArgumentException(Locale.GetText("Invalid XML string") + ": " + value);
}
this.tag = value;
}
}
/// Gets or sets the text within an XML element.
/// The value of the text within an XML element.
/// The text is not valid in XML.
// Token: 0x17000A98 RID: 2712
// (get) Token: 0x0600362F RID: 13871 RVA: 0x000B95E8 File Offset: 0x000B77E8
// (set) Token: 0x06003630 RID: 13872 RVA: 0x000B95F0 File Offset: 0x000B77F0
public string Text
{
get
{
return this.text;
}
set
{
if (value != null && !SecurityElement.IsValidText(value))
{
throw new ArgumentException(Locale.GetText("Invalid XML string") + ": " + value);
}
this.text = SecurityElement.Unescape(value);
}
}
/// Adds a name/value attribute to an XML element.
/// The name of the attribute.
/// The value of the attribute.
/// The parameter or parameter is null.
/// The parameter or parameter is invalid in XML.-or- An attribute with the name specified by the parameter already exists.
// Token: 0x06003631 RID: 13873 RVA: 0x000B9638 File Offset: 0x000B7838
public void AddAttribute(string name, string value)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
if (value == null)
{
throw new ArgumentNullException("value");
}
if (this.GetAttribute(name) != null)
{
throw new ArgumentException(Locale.GetText("Duplicate attribute : " + name));
}
if (this.attributes == null)
{
this.attributes = new ArrayList();
}
this.attributes.Add(new SecurityElement.SecurityAttribute(name, value));
}
/// Adds a child element to the XML element.
/// The child element to add.
/// The parameter is null.
// Token: 0x06003632 RID: 13874 RVA: 0x000B96B4 File Offset: 0x000B78B4
public void AddChild(SecurityElement child)
{
if (child == null)
{
throw new ArgumentNullException("child");
}
if (this.children == null)
{
this.children = new ArrayList();
}
this.children.Add(child);
}
/// Finds an attribute by name in an XML element.
/// The value associated with the named attribute, or null if no attribute with exists.
/// The name of the attribute for which to search.
/// The parameter is null.
// Token: 0x06003633 RID: 13875 RVA: 0x000B96F8 File Offset: 0x000B78F8
public string Attribute(string name)
{
if (name == null)
{
throw new ArgumentNullException("name");
}
SecurityElement.SecurityAttribute attribute = this.GetAttribute(name);
return (attribute != null) ? attribute.Value : null;
}
/// Creates and returns an identical copy of the current object.
/// A copy of the current object.
// Token: 0x06003634 RID: 13876 RVA: 0x000B9730 File Offset: 0x000B7930
[ComVisible(false)]
public SecurityElement Copy()
{
return new SecurityElement(this);
}
/// Compares two XML element objects for equality.
/// true if the tag, attribute names and values, child elements, and text fields in the current XML element are identical to their counterparts in the parameter; otherwise, false.
/// An XML element object to which to compare the current XML element object.
// Token: 0x06003635 RID: 13877 RVA: 0x000B9738 File Offset: 0x000B7938
public bool Equal(SecurityElement other)
{
if (other == null)
{
return false;
}
if (this == other)
{
return true;
}
if (this.text != other.text)
{
return false;
}
if (this.tag != other.tag)
{
return false;
}
if (this.attributes == null && other.attributes != null && other.attributes.Count != 0)
{
return false;
}
if (other.attributes == null && this.attributes != null && this.attributes.Count != 0)
{
return false;
}
if (this.attributes != null && other.attributes != null)
{
if (this.attributes.Count != other.attributes.Count)
{
return false;
}
foreach (object obj in this.attributes)
{
SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
SecurityElement.SecurityAttribute attribute = other.GetAttribute(securityAttribute.Name);
if (attribute == null || securityAttribute.Value != attribute.Value)
{
return false;
}
}
}
if (this.children == null && other.children != null && other.children.Count != 0)
{
return false;
}
if (other.children == null && this.children != null && this.children.Count != 0)
{
return false;
}
if (this.children != null && other.children != null)
{
if (this.children.Count != other.children.Count)
{
return false;
}
for (int i = 0; i < this.children.Count; i++)
{
if (!((SecurityElement)this.children[i]).Equal((SecurityElement)other.children[i]))
{
return false;
}
}
}
return true;
}
/// Replaces invalid XML characters in a string with their valid XML equivalent.
/// The input string with invalid characters replaced.
/// The string within which to escape invalid characters.
// Token: 0x06003636 RID: 13878 RVA: 0x000B996C File Offset: 0x000B7B6C
public static string Escape(string str)
{
if (str == null)
{
return null;
}
if (str.IndexOfAny(SecurityElement.invalid_chars) == -1)
{
return str;
}
StringBuilder stringBuilder = new StringBuilder();
int length = str.Length;
for (int i = 0; i < length; i++)
{
char c = str[i];
char c2 = c;
switch (c2)
{
case '"':
stringBuilder.Append(""");
break;
default:
switch (c2)
{
case '<':
stringBuilder.Append("<");
goto IL_D9;
case '>':
stringBuilder.Append(">");
goto IL_D9;
}
stringBuilder.Append(c);
break;
case '&':
stringBuilder.Append("&");
break;
case '\'':
stringBuilder.Append("'");
break;
}
IL_D9:;
}
return stringBuilder.ToString();
}
// Token: 0x06003637 RID: 13879 RVA: 0x000B9A64 File Offset: 0x000B7C64
private static string Unescape(string str)
{
if (str == null)
{
return null;
}
StringBuilder stringBuilder = new StringBuilder(str);
stringBuilder.Replace("<", "<");
stringBuilder.Replace(">", ">");
stringBuilder.Replace("&", "&");
stringBuilder.Replace(""", "\"");
stringBuilder.Replace("'", "'");
return stringBuilder.ToString();
}
/// Creates a security element from an XML-encoded string.
/// A created from the XML.
/// The XML-encoded string from which to create the security element.
///
/// contains one or more single quotation mark characters.
///
/// is null.
// Token: 0x06003638 RID: 13880 RVA: 0x000B9ADC File Offset: 0x000B7CDC
public static SecurityElement FromString(string xml)
{
if (xml == null)
{
throw new ArgumentNullException("xml");
}
if (xml.Length == 0)
{
throw new XmlSyntaxException(Locale.GetText("Empty string."));
}
SecurityElement securityElement;
try
{
SecurityParser securityParser = new SecurityParser();
securityParser.LoadXml(xml);
securityElement = securityParser.ToXml();
}
catch (Exception ex)
{
string text = Locale.GetText("Invalid XML.");
throw new XmlSyntaxException(text, ex);
}
return securityElement;
}
/// Determines whether a string is a valid attribute name.
/// true if the parameter is a valid XML attribute name; otherwise, false.
/// The attribute name to test for validity.
// Token: 0x06003639 RID: 13881 RVA: 0x000B9B6C File Offset: 0x000B7D6C
public static bool IsValidAttributeName(string name)
{
return name != null && name.IndexOfAny(SecurityElement.invalid_attr_name_chars) == -1;
}
/// Determines whether a string is a valid attribute value.
/// true if the parameter is a valid XML attribute value; otherwise, false.
/// The attribute value to test for validity.
// Token: 0x0600363A RID: 13882 RVA: 0x000B9B88 File Offset: 0x000B7D88
public static bool IsValidAttributeValue(string value)
{
return value != null && value.IndexOfAny(SecurityElement.invalid_attr_value_chars) == -1;
}
/// Determines whether a string is a valid tag.
/// true if the parameter is a valid XML tag; otherwise, false.
/// The tag to test for validity.
// Token: 0x0600363B RID: 13883 RVA: 0x000B9BA4 File Offset: 0x000B7DA4
public static bool IsValidTag(string tag)
{
return tag != null && tag.IndexOfAny(SecurityElement.invalid_tag_chars) == -1;
}
/// Determines whether a string is valid as text within an XML element.
/// true if the parameter is a valid XML text element; otherwise, false.
/// The text to test for validity.
// Token: 0x0600363C RID: 13884 RVA: 0x000B9BC0 File Offset: 0x000B7DC0
public static bool IsValidText(string text)
{
return text != null && text.IndexOfAny(SecurityElement.invalid_text_chars) == -1;
}
/// Finds a child by its tag name.
/// The first child XML element with the specified tag value, or null if no child element with exists.
/// The tag for which to search in child elements.
/// The parameter is null.
// Token: 0x0600363D RID: 13885 RVA: 0x000B9BDC File Offset: 0x000B7DDC
public SecurityElement SearchForChildByTag(string tag)
{
if (tag == null)
{
throw new ArgumentNullException("tag");
}
if (this.children == null)
{
return null;
}
for (int i = 0; i < this.children.Count; i++)
{
SecurityElement securityElement = (SecurityElement)this.children[i];
if (securityElement.tag == tag)
{
return securityElement;
}
}
return null;
}
/// Finds a child by its tag name and returns the contained text.
/// The text contents of the first child element with the specified tag value.
/// The tag for which to search in child elements.
///
/// is null.
// Token: 0x0600363E RID: 13886 RVA: 0x000B9C4C File Offset: 0x000B7E4C
public string SearchForTextOfTag(string tag)
{
if (tag == null)
{
throw new ArgumentNullException("tag");
}
if (this.tag == tag)
{
return this.text;
}
if (this.children == null)
{
return null;
}
for (int i = 0; i < this.children.Count; i++)
{
string text = ((SecurityElement)this.children[i]).SearchForTextOfTag(tag);
if (text != null)
{
return text;
}
}
return null;
}
/// Produces a string representation of an XML element and its constituent attributes, child elements, and text.
/// The XML element and its contents.
// Token: 0x0600363F RID: 13887 RVA: 0x000B9CCC File Offset: 0x000B7ECC
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
this.ToXml(ref stringBuilder, 0);
return stringBuilder.ToString();
}
// Token: 0x06003640 RID: 13888 RVA: 0x000B9CF0 File Offset: 0x000B7EF0
private void ToXml(ref StringBuilder s, int level)
{
s.Append("<");
s.Append(this.tag);
if (this.attributes != null)
{
s.Append(" ");
for (int i = 0; i < this.attributes.Count; i++)
{
SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)this.attributes[i];
s.Append(securityAttribute.Name).Append("=\"").Append(SecurityElement.Escape(securityAttribute.Value))
.Append("\"");
if (i != this.attributes.Count - 1)
{
s.Append(Environment.NewLine);
}
}
}
if ((this.text == null || this.text == string.Empty) && (this.children == null || this.children.Count == 0))
{
s.Append("/>").Append(Environment.NewLine);
}
else
{
s.Append(">").Append(SecurityElement.Escape(this.text));
if (this.children != null)
{
s.Append(Environment.NewLine);
foreach (object obj in this.children)
{
SecurityElement securityElement = (SecurityElement)obj;
securityElement.ToXml(ref s, level + 1);
}
}
s.Append("").Append(this.tag).Append(">")
.Append(Environment.NewLine);
}
}
// Token: 0x06003641 RID: 13889 RVA: 0x000B9ED0 File Offset: 0x000B80D0
internal SecurityElement.SecurityAttribute GetAttribute(string name)
{
if (this.attributes != null)
{
foreach (object obj in this.attributes)
{
SecurityElement.SecurityAttribute securityAttribute = (SecurityElement.SecurityAttribute)obj;
if (securityAttribute.Name == name)
{
return securityAttribute;
}
}
}
return null;
}
// Token: 0x0400162C RID: 5676
private string text;
// Token: 0x0400162D RID: 5677
private string tag;
// Token: 0x0400162E RID: 5678
private ArrayList attributes;
// Token: 0x0400162F RID: 5679
private ArrayList children;
// Token: 0x04001630 RID: 5680
private static readonly char[] invalid_tag_chars = new char[] { ' ', '<', '>' };
// Token: 0x04001631 RID: 5681
private static readonly char[] invalid_text_chars = new char[] { '<', '>' };
// Token: 0x04001632 RID: 5682
private static readonly char[] invalid_attr_name_chars = new char[] { ' ', '<', '>' };
// Token: 0x04001633 RID: 5683
private static readonly char[] invalid_attr_value_chars = new char[] { '"', '<', '>' };
// Token: 0x04001634 RID: 5684
private static readonly char[] invalid_chars = new char[] { '<', '>', '"', '\'', '&' };
// Token: 0x020005CE RID: 1486
internal class SecurityAttribute
{
// Token: 0x06003642 RID: 13890 RVA: 0x000B9F60 File Offset: 0x000B8160
public SecurityAttribute(string name, string value)
{
if (!SecurityElement.IsValidAttributeName(name))
{
throw new ArgumentException(Locale.GetText("Invalid XML attribute name") + ": " + name);
}
if (!SecurityElement.IsValidAttributeValue(value))
{
throw new ArgumentException(Locale.GetText("Invalid XML attribute value") + ": " + value);
}
this._name = name;
this._value = SecurityElement.Unescape(value);
}
// Token: 0x17000A99 RID: 2713
// (get) Token: 0x06003643 RID: 13891 RVA: 0x000B9FD4 File Offset: 0x000B81D4
public string Name
{
get
{
return this._name;
}
}
// Token: 0x17000A9A RID: 2714
// (get) Token: 0x06003644 RID: 13892 RVA: 0x000B9FDC File Offset: 0x000B81DC
public string Value
{
get
{
return this._value;
}
}
// Token: 0x04001635 RID: 5685
private string _name;
// Token: 0x04001636 RID: 5686
private string _value;
}
}
}