MS.StrongNameSignatures.cs
1 using System;2 using System.Diagnostics;3 using System.Globalization;4 using System.IO;5 using MS.StrongName.Native;6 7 namespace MS.StrongName8 {9 /// <summary>10 /// Class that exposes the managed StrongName API for dealing with signatures11 /// </summary>12 public static class Signatures13 {14 /// <summary>15 /// Verify an assembly's strong name16 /// </summary>17 /// <exception cref="ArgumentNullException">18 /// If <paramref name="signedAssembly"/> is null19 /// </exception>20 /// <exception cref="ArgumentException">21 /// If <paramref name="signedAssembly"/> is empty22 /// </exception>23 /// <exception cref="InvalidOperationException">24 /// If verification could not complete25 /// </exception>26 /// <param name="signedAssembly">assembly to verify</param>27 /// <param name="forceVerification">true to ignore the skip verify registry </param>28 /// <returns>result of the strong name verification</returns>29 public static VerificationResult VerifyAssembly(string signedAssembly, bool forceVerification)30 {31 if(signedAssembly == null)32 throw new ArgumentNullException("signedAssembly");33 if(String.IsNullOrEmpty(signedAssembly))34 throw new ArgumentException(Resources.InvalidAssemblyName, String.Empty);35 36 // make sure the assembly is there37 if(!File.Exists(signedAssembly))38 throw new InvalidOperationException(String.Format(39 CultureInfo.CurrentCulture,40 Resources.NoAssembly,41 signedAssembly));42 43 // do the verification44 bool notForced = false;45 bool passedVerification = NativeMethods.StrongNameSignatureVerificationEx(46 signedAssembly,47 forceVerification,48 ref notForced);49 50 if(passedVerification && notForced)51 return VerificationResult.Verified;52 else if(passedVerification && !notForced)53 return VerificationResult.DelaySigned;54 else55 return VerificationResult.NotVerified;56 }57 }58 }