Explorar el Código

2002-12-15 Sebastien Pouliot <[email protected]>

	* Publisher.cs: New. Implemented.
	* PublisherMembershipCondition.cs: New. X509 related stuff implemented.

svn path=/trunk/mcs/; revision=9696
Sebastien Pouliot hace 23 años
padre
commit
389cd4bee6

+ 5 - 0
mcs/class/corlib/System.Security.Policy/ChangeLog

@@ -1,3 +1,8 @@
+2002-12-15  Sebastien Pouliot  <[email protected]>
+
+	* Publisher.cs: New. Implemented.
+	* PublisherMembershipCondition.cs: New. X509 related stuff implemented.
+
 2002-11-28 Jackson Harper <[email protected]>
 
 	* NetCodeGroup.cs: Added file

+ 85 - 0
mcs/class/corlib/System.Security.Policy/Publisher.cs

@@ -0,0 +1,85 @@
+//
+// Publisher.cs: Publisher Policy using X509 Certificate
+//
+// Author:
+//	Sebastien Pouliot ([email protected])
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Security.Cryptography.X509Certificates;
+using System.Security.Permissions;
+using System.Text;
+
+namespace System.Security.Policy {
+
+[Serializable]
+public sealed class Publisher : IIdentityPermissionFactory {
+	
+	private X509Certificate x509;
+
+	public Publisher (X509Certificate cert) 
+	{
+		if (cert == null)
+			throw new ArgumentNullException ("cert");
+		x509 = cert;
+	}
+
+	~Publisher () 
+	{
+		// X509Certificate doesn't have a Dispose 
+		// (bad design as it deal with unmanaged code in Windows)
+		// not really needed but corcompare will be happier
+	}
+
+	public X509Certificate Certificate { 
+		get { 
+			// needed to match MS implementation
+			if (x509.GetRawCertData() == null)
+				throw new NullReferenceException ("x509");
+			return x509; 
+		}
+	}
+
+	public object Copy () 
+	{
+		return (object) new Publisher (x509);
+	}
+
+	[MonoTODO("What should we do with the evidence ? nothing?")]
+	public IPermission CreateIdentityPermission (Evidence evidence) 
+	{
+		return new PublisherIdentityPermission (x509);
+	}
+
+	public override bool Equals (object o) 
+	{
+		if (!(o is Publisher))
+			throw new ArgumentException ("not a Publisher");
+		return x509.Equals ((o as Publisher).Certificate);
+	}
+	
+	public override int GetHashCode () 
+	{
+		return x509.GetHashCode ();
+	}
+
+	public override string ToString ()
+	{
+		StringBuilder sb = new StringBuilder ();
+		sb.Append ("<System.Security.Policy.Publisher version=\"1\">\r\n   <X509v3Certificate");
+		string cert = x509.GetRawCertDataString ();
+		if (cert == null)
+			sb.Append ("/>\r\n");
+		else {
+			sb.Append (">");
+			sb.Append (cert);
+			sb.Append ("</X509v3Certificate>\r\n");
+		}
+		sb.Append ("</System.Security.Policy.Publisher>\r\n");
+		return sb.ToString ();
+	}
+}
+
+}

+ 90 - 0
mcs/class/corlib/System.Security.Policy/PublisherMembershipCondition.cs

@@ -0,0 +1,90 @@
+//
+// PublisherMembershipCondition.cs: Publisher Membership Condition
+//
+// Author:
+//	Sebastien Pouliot ([email protected])
+//
+// (C) 2002 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using System;
+using System.Security.Cryptography.X509Certificates;
+
+namespace System.Security.Policy {
+
+public sealed class PublisherMembershipCondition : IMembershipCondition, ISecurityEncodable, ISecurityPolicyEncodable {
+
+	private X509Certificate x509;
+
+	// LAMESPEC: Undocumented ArgumentNullException exception
+	public PublisherMembershipCondition (X509Certificate certificate) 
+	{
+		if (certificate == null)
+			throw new ArgumentNullException ("certificate");
+		// needed to match MS implementation
+		if (certificate.GetRawCertData() == null)
+			throw new NullReferenceException ("certificate");
+		x509 = certificate;
+	}
+
+	public X509Certificate Certificate {
+		get { return x509; }
+		set { 
+			if (value == null)
+				throw new ArgumentNullException ("value");
+			x509 = value; 
+		}
+	}
+
+	[MonoTODO()]
+	public bool Check (Evidence evidence) 
+	{
+		return true;
+	}
+
+	public IMembershipCondition Copy () 
+	{
+		return new PublisherMembershipCondition (x509);
+	}
+
+	public override bool Equals (object o) 
+	{
+		if (!(o is PublisherMembershipCondition))
+			throw new ArgumentException ("not a PublisherMembershipCondition");
+		return x509.Equals ((o as PublisherMembershipCondition).Certificate);
+	}
+
+	[MonoTODO()]
+	public void FromXml (SecurityElement e) 
+	{
+	}
+
+	[MonoTODO()]
+	public void FromXml (SecurityElement e, PolicyLevel level) 
+	{
+	}
+
+	public override int GetHashCode () 
+	{
+		return x509.GetHashCode ();
+	}
+
+	public override string ToString () 
+	{
+		return "Publisher - " + x509.GetPublicKeyString ();
+	}
+
+	[MonoTODO()]
+	public SecurityElement ToXml () 
+	{
+		return null;
+	}
+
+	[MonoTODO()]
+	public SecurityElement ToXml (PolicyLevel level) 
+	{
+		return null;
+	}
+}
+
+}