6389818fd19e0ad14c34be25e24cb2c8e89c7ba0
[mono.git] / mcs / class / referencesource / System.IdentityModel / System / ServiceModel / Security / BinarySecretKeyIdentifierClause.cs
1 //------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //------------------------------------------------------------
4
5 namespace System.ServiceModel.Security
6 {
7     using System.IdentityModel;
8     using System.IdentityModel.Tokens;
9     using System.Runtime.CompilerServices;
10
11     [TypeForwardedFrom("System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
12     public class BinarySecretKeyIdentifierClause : BinaryKeyIdentifierClause
13     {
14         InMemorySymmetricSecurityKey symmetricKey;
15
16         public BinarySecretKeyIdentifierClause(byte[] key)
17             : this(key, true)
18         {
19         }
20
21         public BinarySecretKeyIdentifierClause(byte[] key, bool cloneBuffer)
22             : this(key, cloneBuffer, null, 0)
23         {
24         }
25
26         public BinarySecretKeyIdentifierClause(byte[] key, bool cloneBuffer, byte[] derivationNonce, int derivationLength)
27             : base(XD.TrustFeb2005Dictionary.BinarySecretClauseType.Value, key, cloneBuffer, derivationNonce, derivationLength)
28         {
29         }
30
31         public byte[] GetKeyBytes()
32         {
33             return GetBuffer();
34         }
35
36         public override bool CanCreateKey
37         {
38             get { return true; }
39         }
40
41         public override SecurityKey CreateKey()
42         {
43             if (this.symmetricKey == null)
44                 this.symmetricKey = new InMemorySymmetricSecurityKey(GetBuffer(), false);
45
46             return this.symmetricKey;
47         }
48
49         public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause)
50         {
51             BinarySecretKeyIdentifierClause that = keyIdentifierClause as BinarySecretKeyIdentifierClause;
52
53             // PreSharp 
54 #pragma warning suppress 56506
55             return ReferenceEquals(this, that) || (that != null && that.Matches(this.GetRawBuffer()));
56         }
57     }
58 }