| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.IdentityModel.Tokens; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF.IdentityModel |
| | | 8 | | { |
| | | 9 | | // All subclasses are required to be thread-safe and immutable |
| | | 10 | | |
| | | 11 | | // Self-resolving clauses such as RSA and X509 raw data should |
| | | 12 | | // override CanCreateKey and return true, and implement |
| | | 13 | | // CreateKey() |
| | | 14 | | |
| | | 15 | | public abstract class SecurityKeyIdentifierClause |
| | | 16 | | { |
| | | 17 | | private readonly byte[] _derivationNonce; |
| | | 18 | | |
| | | 19 | | protected SecurityKeyIdentifierClause(string clauseType) |
| | 0 | 20 | | : this(clauseType, null, 0) |
| | | 21 | | { |
| | 0 | 22 | | } |
| | | 23 | | |
| | 119 | 24 | | protected SecurityKeyIdentifierClause(string clauseType, byte[] nonce, int length) |
| | | 25 | | { |
| | 119 | 26 | | ClauseType = clauseType; |
| | 119 | 27 | | _derivationNonce = nonce; |
| | 119 | 28 | | DerivationLength = length; |
| | 119 | 29 | | } |
| | | 30 | | |
| | | 31 | | public virtual bool CanCreateKey |
| | | 32 | | { |
| | 0 | 33 | | get { return false; } |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | public string ClauseType { get; } |
| | | 37 | | |
| | 1 | 38 | | public string Id { get; set; } = null; |
| | | 39 | | |
| | | 40 | | public virtual SecurityKey CreateKey() |
| | | 41 | | { |
| | 0 | 42 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.KeyIdentifierClauseDo |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public virtual bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 46 | | { |
| | 0 | 47 | | return ReferenceEquals(this, keyIdentifierClause); |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public byte[] GetDerivationNonce() |
| | | 51 | | { |
| | 23 | 52 | | return (_derivationNonce != null) ? (byte[])_derivationNonce.Clone() : null; |
| | | 53 | | } |
| | | 54 | | |
| | 0 | 55 | | public int DerivationLength { get; } |
| | | 56 | | } |
| | | 57 | | } |