本文整理汇总了C#中SecurityElement类的典型用法代码示例。如果您正苦于以下问题:C# SecurityElement类的具体用法?C# SecurityElement怎么用?C# SecurityElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityElement类属于命名空间,在下文中一共展示了SecurityElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Element
// snippet moved from FileIOPermission (nickd) to be reused in all derived classes
internal static SecurityElement Element (Type type, int version)
{
SecurityElement se = new SecurityElement ("IPermission");
se.AddAttribute ("class", type.FullName + ", " + type.Assembly.ToString ().Replace ('\"', '\''));
se.AddAttribute ("version", version.ToString ());
return se;
}
示例2: Test
public static Boolean Test()
{
Boolean bRes = true;
SecurityElement el = new SecurityElement("whatever");
// el.Text = "<Key>RSA</Key><Digest>SHA1</Digest><Formatter>System.Security.Cryptography.RSAPKCS1SignatureFormatter</Formatter><Deformatter>System.Security.Cryptography.RSAPKCS1SignatureFormatter</Deformatter>";
SecurityElement el_key = new SecurityElement("Key");
el_key.Text = "RSA";
SecurityElement el_digest = new SecurityElement("Digest");
el_digest.Text = "SHA1";
SecurityElement el_form = new SecurityElement("Formatter");
el_form.Text = "System.Security.Cryptography.RSAPKCS1SignatureFormatter";
SecurityElement el_deform = new SecurityElement("Deformatter");
el_deform.Text = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter";
el.AddChild(el_key);
el.AddChild(el_digest);
el.AddChild(el_form);
el.AddChild(el_deform);
SignatureDescription sd_empty = new SignatureDescription();
SignatureDescription sd = new SignatureDescription(el);
Console.WriteLine(sd.CreateDigest());
Console.WriteLine(sd.CreateFormatter(RSA.Create()));
Console.WriteLine(sd.CreateDeformatter(RSA.Create()));
return bRes;
}
示例3: ToXml
public SecurityElement ToXml( PolicyLevel level )
{
SecurityElement root = new SecurityElement( "IMembershipCondition" );
System.Security.Util.XMLUtil.AddClassAttribute( root, this.GetType(), this.GetType().FullName );
root.AddAttribute( "version", "1" );
return root;
}
示例4: ApplicationTrustCallMethods
public static void ApplicationTrustCallMethods()
{
ApplicationTrust at = new ApplicationTrust();
SecurityElement se = new SecurityElement("");
at.FromXml(se);
se = at.ToXml();
}
示例5: FromXml
public void FromXml (SecurityElement e, PolicyLevel level)
{
MembershipConditionHelper.CheckSecurityElement (e, "e", version, version);
if (!Boolean.TryParse (e.Attribute ("LookAtDir"), out _lookAtDir))
_lookAtDir = false;
// PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references
}
示例6: ToString
// Convert this object into a string.
public override String ToString()
{
SecurityElement element = new SecurityElement
("System.Security.Policy.PermissionRequestEvidence");
SecurityElement child;
element.AddAttribute("version", "1");
if(request != null)
{
child = new SecurityElement("Request");
child.AddChild(request.ToXml());
element.AddChild(child);
}
if(optional != null)
{
child = new SecurityElement("Optional");
child.AddChild(optional.ToXml());
element.AddChild(child);
}
if(denied != null)
{
child = new SecurityElement("Denied");
child.AddChild(denied.ToXml());
element.AddChild(child);
}
return element.ToString();
}
示例7: SignatureDescription
public SignatureDescription(SecurityElement el)
{
if(el == null)
{
throw new ArgumentNullException("el");
}
foreach(SecurityElement e in el.Children)
{
if(e.Tag == "Deformatter")
{
deformatter = e.Text;
}
else if(e.Tag == "Digest")
{
digest = e.Text;
}
else if(e.Tag == "Formatter")
{
formatter = e.Text;
}
else if(e.Tag == "Key")
{
key = e.Text;
}
}
}
示例8: FromXml
public override void FromXml (SecurityElement securityElement)
{
// General validation in CodeAccessPermission
CheckSecurityElement (securityElement, "securityElement", version, version);
// Note: we do not (yet) care about the return value
// as we only accept version 1 (min/max values)
}
示例9: IDRole
internal IDRole(SecurityElement e)
{
string elAuth = e.Attribute("Authenticated");
Authenticated = elAuth == null ? false : string.Equals(elAuth, "true", StringComparison.OrdinalIgnoreCase);
ID = e.Attribute("ID");
Role = e.Attribute("Role");
}
示例10: CheckSecurityElement
internal static int CheckSecurityElement (SecurityElement se, string parameterName, int minimumVersion, int maximumVersion)
{
if (se == null)
throw new ArgumentNullException (parameterName);
if (se.Attribute ("class") == null) {
string msg = Locale.GetText ("Missing 'class' attribute.");
throw new ArgumentException (msg, parameterName);
}
// we assume minimum version if no version number is supplied
int version = minimumVersion;
string v = se.Attribute ("version");
if (v != null) {
try {
version = Int32.Parse (v);
}
catch (Exception e) {
string msg = Locale.GetText ("Couldn't parse version from '{0}'.");
msg = String.Format (msg, v);
throw new ArgumentException (msg, parameterName, e);
}
}
if ((version < minimumVersion) || (version > maximumVersion)) {
string msg = Locale.GetText ("Unknown version '{0}', expected versions between ['{1}','{2}'].");
msg = String.Format (msg, version, minimumVersion, maximumVersion);
throw new ArgumentException (msg, parameterName);
}
return version;
}
示例11: TestSecurityElementConstructor
// Test the constructor.
public void TestSecurityElementConstructor()
{
SecurityElement e;
try
{
e = new SecurityElement(null);
Fail("Constructor (1)");
}
catch(ArgumentNullException)
{
// Success.
}
try
{
e = new SecurityElement("");
Fail("Constructor (2)");
}
catch(ArgumentException)
{
// Success.
}
try
{
e = new SecurityElement("<");
Fail("Constructor (3)");
}
catch(ArgumentException)
{
// Success.
}
try
{
e = new SecurityElement("a", "<");
Fail("Constructor (4)");
}
catch(ArgumentException)
{
// Success.
}
try
{
e = new SecurityElement("&");
Fail("Constructor (5)");
}
catch(ArgumentException)
{
// Success.
}
e = new SecurityElement("foo", "bar");
AssertEquals("Constructor (6)", "foo", e.Tag);
AssertEquals("Constructor (7)", "bar", e.Text);
e = new SecurityElement("foo");
AssertEquals("Constructor (8)", "foo", e.Tag);
AssertNull("Constructor (9)", e.Text);
e = new SecurityElement("foo", "&");
AssertEquals("Constructor (10)", "foo", e.Tag);
AssertEquals("Constructor (11)", "&", e.Text);
}
示例12: FromXml
public void FromXml( SecurityElement e, PolicyLevel level )
{
if (e == null)
throw new ArgumentNullException("e");
if (!e.Tag.Equals( "IMembershipCondition" ))
throw new ArgumentException( Environment.GetResourceString( "Argument_MembershipConditionElement" ) );
}
示例13: SignatureDescription
public SignatureDescription(SecurityElement el) {
if (el == null) throw new ArgumentNullException("el");
Contract.EndContractBlock();
_strKey = el.SearchForTextOfTag("Key");
_strDigest = el.SearchForTextOfTag("Digest");
_strFormatter = el.SearchForTextOfTag("Formatter");
_strDeformatter = el.SearchForTextOfTag("Deformatter");
}
示例14: ToXml
} //Union()
public override SecurityElement ToXml()
{
SecurityElement s = new SecurityElement("IPermission");
s.AddAttribute("class","myperm, myperm, Version=1.0.1.0, Culture=neutral, PublicKeyToken=0e8dcc8628396732");
s.AddAttribute("version", "1");
s.AddAttribute("Unrestricted", "true");
return s;
} //ToXml()
示例15: Constructor_SecurityElement_Empty
public void Constructor_SecurityElement_Empty()
{
SecurityElement se = new SecurityElement("xml");
SignatureDescription sig = new SignatureDescription(se);
Assert.Null(sig.KeyAlgorithm);
Assert.Null(sig.DigestAlgorithm);
Assert.Null(sig.FormatterAlgorithm);
Assert.Null(sig.DeformatterAlgorithm);
}