//
// Authors
// Duncan Mak <duncan@ximian.com>
-// Sebastien Pouliot <spouliot@videotron.ca>
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2002 Ximian, Inc. http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System;
using System.IO;
+using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;
+using Mono.Security.Cryptography;
using Mono.Xml;
namespace System.Security.Permissions {
+#if NET_2_0
+ [ComVisible (true)]
+#endif
[AttributeUsage (AttributeTargets.Assembly | AttributeTargets.Class |
AttributeTargets.Struct | AttributeTargets.Constructor |
AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
private string name;
private bool isUnicodeEncoded;
private string xml;
+#if NET_2_0
+ private string hex;
+#endif
// Constructor
public PermissionSetAttribute (SecurityAction action)
}
// Properties
- public string File
- {
+ public string File {
get { return file; }
set { file = value; }
}
-
- public string Name
- {
+#if NET_2_0
+ public string Hex {
+ get { return hex; }
+ set { hex = value; }
+ }
+#endif
+ public string Name {
get { return name; }
set { name = value; }
}
- public bool UnicodeEncoded
- {
+ public bool UnicodeEncoded {
get { return isUnicodeEncoded; }
set { isUnicodeEncoded = value; }
}
- public string XML
- {
+ public string XML {
get { return xml; }
set { xml = value; }
}
private PermissionSet CreateFromXml (string xml)
{
+#if !NET_2_1
SecurityParser sp = new SecurityParser ();
- sp.LoadXml (xml);
+ try {
+ sp.LoadXml (xml);
+ }
+ catch (Mono.Xml.SmallXmlParserException xe) {
+ throw new XmlSyntaxException (xe.Line, xe.ToString ());
+ }
SecurityElement se = sp.ToXml ();
string className = se.Attribute ("class");
return null;
PermissionState state = PermissionState.None;
- if (se.Attribute ("Unrestricted") == "true")
+ if (CodeAccessPermission.IsUnrestricted (se))
state = PermissionState.Unrestricted;
if (className.EndsWith ("NamedPermissionSet")) {
NamedPermissionSet nps = new NamedPermissionSet (se.Attribute ("Name"), state);
+ nps.FromXml (se);
return (PermissionSet) nps;
}
else if (className.EndsWith ("PermissionSet")) {
PermissionSet ps = new PermissionSet (state);
+ ps.FromXml (se);
return ps;
}
+#endif
return null;
}
public PermissionSet CreatePermissionSet ()
{
PermissionSet pset = null;
+#if !NET_2_1
if (this.Unrestricted)
pset = new PermissionSet (PermissionState.Unrestricted);
else {
else if (xml != null) {
pset = CreateFromXml (xml);
}
+#if NET_2_0
+ else if (hex != null) {
+ // Unicode isn't supported
+ //Encoding e = ((isUnicodeEncoded) ? System.Text.Encoding.Unicode : System.Text.Encoding.ASCII);
+ Encoding e = System.Text.Encoding.ASCII;
+ byte[] bin = CryptoConvert.FromHex (hex);
+ pset = CreateFromXml (e.GetString (bin, 0, bin.Length));
+ }
+#endif
}
+#endif
return pset;
}
}