2 // System.Security.Cryptography.CngProperty
4 // Copyright (C) 2011 Juho Vähä-Herttua
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 namespace System.Security.Cryptography {
30 // note: CNG stands for "Cryptography API: Next Generation"
32 public struct CngProperty : IEquatable<CngProperty> {
35 private CngPropertyOptions opts;
37 public CngProperty(string name, byte[] value, CngPropertyOptions options)
40 throw new ArgumentNullException("name");
43 this.val = (value != null) ? (byte[]) value.Clone () : null;
51 public CngPropertyOptions Options {
55 public byte[] GetValue ()
59 return (byte[]) val.Clone ();
62 public bool Equals (CngProperty other)
64 if (this.name != other.name || this.opts != other.opts)
66 if (this.val == null && other.val == null)
68 if (this.val == null || other.val == null)
70 if (this.val.Length != other.val.Length)
73 for (int i=0; i<val.Length; i++) {
74 if (this.val[i] != other.val[i])
80 public override bool Equals (object obj)
84 if (!(obj is CngProperty))
86 return Equals ((CngProperty) obj);
89 public override int GetHashCode ()
91 int ret = name.GetHashCode () ^ opts.GetHashCode ();
95 for (int i=0; i<val.Length; i++) {
96 // Handle each 4 bytes of byte array as a little-endian
97 // integer and XOR it with the resulting hash code value
98 ret ^= val[i] << 8*(i % 4);
105 public static bool operator == (CngProperty left, CngProperty right)
107 return left.Equals (right);
110 public static bool operator != (CngProperty left, CngProperty right)
112 return !left.Equals (right);