Update Reference Sources to .NET Framework 4.6.1
[mono.git] / mcs / class / referencesource / System.IdentityModel / System / ServiceModel / Security / SecurityContextKeyIdentifierClause.cs
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //-----------------------------------------------------------------------------
4 namespace System.ServiceModel.Security
5 {
6     using System.Globalization;
7     using System.IdentityModel.Tokens;
8     using System.Runtime.CompilerServices;
9     using System.Xml;
10     using DiagnosticUtility = System.IdentityModel.DiagnosticUtility;
11
12     [TypeForwardedFrom( "System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" )]
13     public class SecurityContextKeyIdentifierClause : SecurityKeyIdentifierClause
14     {
15         readonly UniqueId contextId;
16         readonly UniqueId generation;
17
18         public SecurityContextKeyIdentifierClause(UniqueId contextId)
19             : this(contextId, null)
20         {
21         }
22
23         public SecurityContextKeyIdentifierClause(UniqueId contextId, UniqueId generation)
24             : this(contextId, generation, null, 0)
25         {
26         }
27
28         public SecurityContextKeyIdentifierClause(UniqueId contextId, UniqueId generation, byte[] derivationNonce, int derivationLength)
29             : base(null, derivationNonce, derivationLength)
30         {
31             if (contextId == null)
32             {
33                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextId");
34             }
35             this.contextId = contextId;
36             this.generation = generation;
37         }
38
39         public UniqueId ContextId
40         {
41             get { return this.contextId; }
42         }
43
44         public UniqueId Generation
45         {
46             get { return this.generation; }
47         }
48
49         public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause)
50         {
51             SecurityContextKeyIdentifierClause that = keyIdentifierClause as SecurityContextKeyIdentifierClause;
52
53             // PreSharp Bug: Parameter 'that' to this public method must be validated: A null-dereference can occur here.
54             #pragma warning suppress 56506
55             return ReferenceEquals(this, that) || (that != null && that.Matches(this.contextId, this.generation));
56         }
57
58         public bool Matches(UniqueId contextId, UniqueId generation)
59         {
60             return contextId == this.contextId && generation == this.generation;
61         }
62
63         public override string ToString()
64         {
65             return string.Format(CultureInfo.InvariantCulture, "SecurityContextKeyIdentifierClause(ContextId = '{0}', Generation = '{1}')",
66                 this.ContextId, this.Generation);
67         }
68     }
69 }