3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 // StrongNamePublicKeyBlob.cs
8 // <OWNER>[....]</OWNER>
11 namespace System.Security.Permissions
14 using System.Security.Util;
15 using System.Diagnostics.Contracts;
17 [System.Runtime.InteropServices.ComVisible(true)]
18 [Serializable] sealed public class StrongNamePublicKeyBlob
20 internal byte[] PublicKey;
22 internal StrongNamePublicKeyBlob()
26 public StrongNamePublicKeyBlob( byte[] publicKey )
28 if (publicKey == null)
29 throw new ArgumentNullException( "PublicKey" );
30 Contract.EndContractBlock();
32 this.PublicKey = new byte[publicKey.Length];
33 Array.Copy( publicKey, 0, this.PublicKey, 0, publicKey.Length );
36 internal StrongNamePublicKeyBlob( String publicKey )
38 this.PublicKey = Hex.DecodeHexString( publicKey );
41 private static bool CompareArrays( byte[] first, byte[] second )
43 if (first.Length != second.Length)
48 int count = first.Length;
49 for (int i = 0; i < count; ++i)
51 if (first[i] != second[i])
59 internal bool Equals( StrongNamePublicKeyBlob blob )
64 return CompareArrays( this.PublicKey, blob.PublicKey );
67 public override bool Equals( Object obj )
69 if (obj == null || !(obj is StrongNamePublicKeyBlob))
72 return this.Equals( (StrongNamePublicKeyBlob)obj );
75 static private int GetByteArrayHashCode( byte[] baData )
82 for (int i = 0; i < baData.Length; ++i)
84 accumulator = (accumulator << 8) ^ (int)baData[i] ^ (accumulator >> 24);
90 public override int GetHashCode()
92 return GetByteArrayHashCode( PublicKey );
95 public override String ToString()
97 return Hex.EncodeHexString( PublicKey );