public static void StrongNamePublicKeyBlobTests() { StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(new byte[1]); bool testbool = snpkb.Equals(new object()); int hash = snpkb.GetHashCode(); string teststring = snpkb.ToString(); }
public void InvalidPublicKey() { StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(bad); // Proof that there's no validation on public key Assert.AreEqual("0BAD", snpkb.ToString(), "ToString(BAD)"); }
public override String ToString() { StringBuilder builder = new StringBuilder(); builder.Append("StrongName - "); builder.Append(blob.ToString()); if (name != null) { builder.Append(" name = "); builder.Append(name); } if (version != null) { builder.Append(" version = "); builder.Append(version.ToString()); } return(builder.ToString()); }
public override string ToString() { SecurityElement element = new SecurityElement(typeof(System.Security.Policy.StrongName).Name); element.AddAttribute("version", "1"); element.AddAttribute("Key", publickey.ToString()); element.AddAttribute("Name", name); element.AddAttribute("Version", version.ToString()); return(element.ToString()); }
// Convert this object into a string. public override String ToString() { SecurityElement element = new SecurityElement("StrongName"); element.AddAttribute("version", "1"); element.AddAttribute("Key", blob.ToString()); element.AddAttribute ("Name", SecurityElement.Escape(name)); element.AddAttribute("Version", version.ToString()); return(element.ToString()); }
public void CompleteConstructor() { StrongName sn = new StrongName(snpkb, name, version); Assert.AreEqual(name, sn.Name, "Name"); Assert.AreEqual(snpkb.ToString(), sn.PublicKey.ToString(), "PublicKey"); Assert.AreEqual(version.ToString(), sn.Version.ToString(), "Version"); // same as StrongNamePublicKeyBlob Assert.AreEqual(snpkb.GetHashCode(), sn.GetHashCode(), "GetHashCode"); IPermission ip = sn.CreateIdentityPermission(null); Assert.IsTrue((ip is StrongNameIdentityPermission), "CreateIdentityPermission"); string s = String.Format("<StrongName version=\"1\"{0}{1}Key=\"00240000048000009400000006020000002400005253413100040000010001003DBD7208C62B0EA8C1C058072B635F7C9ABDCB22DB20B2A9DADAEFE800642F5D8DEB7802F7A5367728D7558D1468DBEB2409D02B131B926E2E59544AAC18CFC909023F4FA83E94001FC2F11A27477D1084F514B861621A0C66ABD24C4B9FC90F3CD8920FF5FFCED76E5C6FB1F57DD356F96727A4A5485B079344004AF8FFA4CB\"{0}{1}Name=\"StrongNameName\"{0}{1}Version=\"1.2.3.4\"/>{0}", Environment.NewLine, String.Empty); Assert.AreEqual(s, sn.ToString(), "ToString"); }
public SecurityElement ToXml(PolicyLevel level) { // PolicyLevel isn't used as there's no need to resolve NamedPermissionSet references SecurityElement se = MembershipConditionHelper.Element(typeof(StrongNameMembershipCondition), version); if (blob != null) { se.AddAttribute("PublicKeyBlob", blob.ToString()); } if (name != null) { se.AddAttribute("Name", name); } if (assemblyVersion != null) { string v = assemblyVersion.ToString(); if (v != "0.0") { se.AddAttribute("AssemblyVersion", v); } } return(se); }
public void PublicKey() { StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(pk); Assert.IsTrue(snpkb.Equals(snpkb), "Equals(Self)"); Assert.IsFalse(snpkb.Equals(null), "Equals(null)"); Assert.AreEqual("00240000048000009400000006020000002400005253413100040000010001003DBD7208C62B0EA8C1C058072B635F7C9ABDCB22DB20B2A9DADAEFE800642F5D8DEB7802F7A5367728D7558D1468DBEB2409D02B131B926E2E59544AAC18CFC909023F4FA83E94001FC2F11A27477D1084F514B861621A0C66ABD24C4B9FC90F3CD8920FF5FFCED76E5C6FB1F57DD356F96727A4A5485B079344004AF8FFA4CB", snpkb.ToString(), "ToString(pk)"); StrongNamePublicKeyBlob snpkb2 = new StrongNamePublicKeyBlob(pk); Assert.IsTrue(snpkb.Equals(snpkb2), "Equals()-true"); StrongNamePublicKeyBlob snpkb3 = new StrongNamePublicKeyBlob(bad); Assert.IsFalse(snpkb.Equals(snpkb3), "Equals()-false"); // non standard get hash code - why ??? Assert.AreEqual(snpkb2.GetHashCode(), snpkb.GetHashCode(), "GetHashCode-0"); #if NET_2_0 // the first 4 bytes has code has been fixed in 2.0 beta 1 #elif NET_1_1 // It seems to be the first four bytes of the public key data // which seems like non sense as all valid public key will have the same header ? Assert.AreEqual(2359296, snpkb.GetHashCode(), "GetHashCode-1"); Assert.AreEqual(2359296, snpkb2.GetHashCode(), "GetHashCode-2"); Assert.AreEqual(2989, snpkb3.GetHashCode(), "GetHashCode-3"); byte[] header = { 0x00, 0x24, 0x00, 0x00 }; StrongNamePublicKeyBlob snpkb4 = new StrongNamePublicKeyBlob(header); Assert.AreEqual(2359296, snpkb4.GetHashCode(), "GetHashCode-4"); #endif }
public static void StrongNamePublicKeyBlobTests() { StrongNamePublicKeyBlob snpkb = new StrongNamePublicKeyBlob(new byte[1]); bool testbool = snpkb.Equals(new object()); int hash = snpkb.GetHashCode(); string teststring = snpkb.ToString(); }
/////////////////////////////////////////////////////////////////////// public static bool IsStrongNameSigned( Assembly assembly, ref byte[] publicKeyToken, ref string error ) { if (assembly == null) { error = "assembly is invalid"; return(false); } AssemblyName assemblyName = assembly.GetName(); if (assemblyName == null) { error = "assembly has invalid name"; return(false); } byte[] publicKey = assemblyName.GetPublicKey(); if (publicKey == null) { error = "assembly has invalid public key"; return(false); } Evidence evidence = assembly.Evidence; if (evidence == null) { error = "assembly has invalid evidence"; return(false); } IEnumerator enumerator = evidence.GetHostEnumerator(); if (enumerator == null) { error = "assembly has invalid evidence enumerator"; return(false); } while (enumerator.MoveNext()) { StrongName strongName = enumerator.Current as StrongName; if (strongName == null) { continue; } StrongNamePublicKeyBlob strongNamePublicKey = strongName.PublicKey; if (strongNamePublicKey == null) { error = "assembly strong name has invalid public key"; return(false); } if (GenericOps <byte> .Equals(ParseOps.HexString( strongNamePublicKey.ToString()), publicKey)) { publicKeyToken = assemblyName.GetPublicKeyToken(); if (publicKeyToken == null) { error = "assembly has invalid public key token"; return(false); } return(true); } } error = "assembly is not signed"; return(false); }