static int Verify (string assemblyName, bool forceVerification, bool quiet)
{
// this doesn't load the assembly (well it unloads it ;)
// http://weblogs.asp.net/nunitaddin/posts/9991.aspx
AssemblyName an = null;
try {
an = AssemblyName.GetAssemblyName (assemblyName);
}
catch {
}
if (an == null) {
Console.WriteLine ("Unable to load assembly: {0}", assemblyName);
return 2;
}
byte[] publicKey = StrongNameManager.GetMappedPublicKey (an.GetPublicKeyToken ());
if ((publicKey == null) || (publicKey.Length < 12)) {
// no mapping
publicKey = an.GetPublicKey ();
if ((publicKey == null) || (publicKey.Length < 12)) {
Console.WriteLine ("{0} is not a strongly named assembly.", assemblyName);
return 2;
}
}
// Note: MustVerify is based on the original token (by design). Public key
// remapping won't affect if the assembly is verified or not.
if (forceVerification || StrongNameManager.MustVerify (an)) {
RSA rsa = CryptoConvert.FromCapiPublicKeyBlob (publicKey, 12);
StrongName sn = new StrongName (rsa);
if (sn.Verify (assemblyName)) {
if (!quiet)
Console.WriteLine ("Assembly {0} is strongnamed.", assemblyName);
return 0;
}
else {
Console.WriteLine ("Assembly {0} is delay-signed but not strongnamed", assemblyName);
return 1;
}
}
else {
Console.WriteLine ("Assembly {0} is strongnamed (verification skipped).", assemblyName);
return 0;
}
}