1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
4 namespace System.ServiceModel.Security
6 using System.Globalization;
7 using System.IdentityModel.Tokens;
8 using System.Runtime.CompilerServices;
10 using DiagnosticUtility = System.IdentityModel.DiagnosticUtility;
12 [TypeForwardedFrom( "System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" )]
13 public class SecurityContextKeyIdentifierClause : SecurityKeyIdentifierClause
15 readonly UniqueId contextId;
16 readonly UniqueId generation;
18 public SecurityContextKeyIdentifierClause(UniqueId contextId)
19 : this(contextId, null)
23 public SecurityContextKeyIdentifierClause(UniqueId contextId, UniqueId generation)
24 : this(contextId, generation, null, 0)
28 public SecurityContextKeyIdentifierClause(UniqueId contextId, UniqueId generation, byte[] derivationNonce, int derivationLength)
29 : base(null, derivationNonce, derivationLength)
31 if (contextId == null)
33 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contextId");
35 this.contextId = contextId;
36 this.generation = generation;
39 public UniqueId ContextId
41 get { return this.contextId; }
44 public UniqueId Generation
46 get { return this.generation; }
49 public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause)
51 SecurityContextKeyIdentifierClause that = keyIdentifierClause as SecurityContextKeyIdentifierClause;
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));
58 public bool Matches(UniqueId contextId, UniqueId generation)
60 return contextId == this.contextId && generation == this.generation;
63 public override string ToString()
65 return string.Format(CultureInfo.InvariantCulture, "SecurityContextKeyIdentifierClause(ContextId = '{0}', Generation = '{1}')",
66 this.ContextId, this.Generation);