mscorlib(4.0.0.0) API with additions
Publisher.cs
1 using System.IO;
5 
7 {
10  [ComVisible(true)]
12  {
13  private X509Certificate m_cert;
14 
18 
23  {
24  if (cert == null)
25  {
26  throw new ArgumentNullException("cert");
27  }
28  m_cert = cert;
29  }
30 
35  {
36  return new PublisherIdentityPermission(m_cert);
37  }
38 
44  public override bool Equals(object o)
45  {
46  Publisher publisher = o as Publisher;
47  if (publisher != null)
48  {
49  return PublicKeyEquals(m_cert, publisher.m_cert);
50  }
51  return false;
52  }
53 
54  internal static bool PublicKeyEquals(X509Certificate cert1, X509Certificate cert2)
55  {
56  if (cert1 == null)
57  {
58  return cert2 == null;
59  }
60  if (cert2 == null)
61  {
62  return false;
63  }
64  byte[] publicKey = cert1.GetPublicKey();
65  string keyAlgorithm = cert1.GetKeyAlgorithm();
66  byte[] keyAlgorithmParameters = cert1.GetKeyAlgorithmParameters();
67  byte[] publicKey2 = cert2.GetPublicKey();
68  string keyAlgorithm2 = cert2.GetKeyAlgorithm();
69  byte[] keyAlgorithmParameters2 = cert2.GetKeyAlgorithmParameters();
70  int num = publicKey.Length;
71  if (num != publicKey2.Length)
72  {
73  return false;
74  }
75  for (int i = 0; i < num; i++)
76  {
77  if (publicKey[i] != publicKey2[i])
78  {
79  return false;
80  }
81  }
82  if (!keyAlgorithm.Equals(keyAlgorithm2))
83  {
84  return false;
85  }
86  num = keyAlgorithmParameters.Length;
87  if (keyAlgorithmParameters2.Length != num)
88  {
89  return false;
90  }
91  for (int j = 0; j < num; j++)
92  {
93  if (keyAlgorithmParameters[j] != keyAlgorithmParameters2[j])
94  {
95  return false;
96  }
97  }
98  return true;
99  }
100 
103  public override int GetHashCode()
104  {
105  return m_cert.GetHashCode();
106  }
107 
110  public override EvidenceBase Clone()
111  {
112  return new Publisher(m_cert);
113  }
114 
117  public object Copy()
118  {
119  return Clone();
120  }
121 
122  internal SecurityElement ToXml()
123  {
124  SecurityElement securityElement = new SecurityElement("System.Security.Policy.Publisher");
125  securityElement.AddAttribute("version", "1");
126  securityElement.AddChild(new SecurityElement("X509v3Certificate", (m_cert != null) ? m_cert.GetRawCertDataString() : ""));
127  return securityElement;
128  }
129 
132  public override string ToString()
133  {
134  return ToXml().ToString();
135  }
136 
137  internal object Normalize()
138  {
139  MemoryStream memoryStream = new MemoryStream(m_cert.GetRawCertData());
140  memoryStream.Position = 0L;
141  return memoryStream;
142  }
143  }
144 }
override bool Equals(object o)
Compares the current T:System.Security.Policy.Publisher to the specified object for equivalence.
Definition: Publisher.cs:44
virtual string GetKeyAlgorithm()
Returns the key algorithm information for this X.509v3 certificate as a string.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Provides the Authenticode X.509v3 digital signature of a code assembly as evidence for policy evaluat...
Definition: Publisher.cs:11
Definition: __Canon.cs:3
Provides a base class from which all objects to be used as evidence must derive.
Definition: EvidenceBase.cs:12
object Copy()
Creates an equivalent copy of the T:System.Security.Policy.Publisher.
Definition: Publisher.cs:117
virtual byte [] GetKeyAlgorithmParameters()
Returns the key algorithm parameters for the X.509v3 certificate as an array of bytes.
Defines the method that creates a new identity permission.
void AddChild(SecurityElement child)
Adds a child element to the XML element.
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
override string ToString()
Returns a string representation of the current T:System.Security.Policy.Publisher.
Definition: Publisher.cs:132
IPermission CreateIdentityPermission(Evidence evidence)
Creates an identity permission that corresponds to the current instance of the T:System....
Definition: Publisher.cs:34
Represents the XML object model for encoding security objects. This class cannot be inherited.
override EvidenceBase Clone()
Creates a new object that is a copy of the current instance.
Definition: Publisher.cs:110
override int GetHashCode()
Gets the hash code of the current P:System.Security.Policy.Publisher.Certificate.
Definition: Publisher.cs:103
Defines methods implemented by permission types.
Definition: IPermission.cs:7
X509Certificate Certificate
Gets the publisher's Authenticode X.509v3 certificate.
Definition: Publisher.cs:17
Represents the identity of a software publisher. This class cannot be inherited.
Publisher(X509Certificate cert)
Initializes a new instance of the T:System.Security.Policy.Publisher class with the Authenticode X....
Definition: Publisher.cs:22
virtual byte [] GetPublicKey()
Returns the public key for the X.509v3 certificate as an array of bytes.
Defines the set of information that constitutes input to security policy decisions....
Definition: Evidence.cs:17
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
override long Position
Gets or sets the current position within the stream.
override string ToString()
Produces a string representation of an XML element and its constituent attributes,...
Provides methods that help you use X.509 v.3 certificates.