| | | 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.Security; |
| | | 6 | | using HexBinary = CoreWCF.Security.SoapHexBinary; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 9 | | { |
| | | 10 | | public abstract class BinaryKeyIdentifierClause : SecurityKeyIdentifierClause |
| | | 11 | | { |
| | | 12 | | private readonly byte[] _identificationData; |
| | | 13 | | |
| | | 14 | | protected BinaryKeyIdentifierClause(string clauseType, byte[] identificationData, bool cloneBuffer) |
| | 52 | 15 | | : this(clauseType, identificationData, cloneBuffer, null, 0) |
| | | 16 | | { |
| | 52 | 17 | | } |
| | | 18 | | |
| | | 19 | | protected BinaryKeyIdentifierClause(string clauseType, byte[] identificationData, bool cloneBuffer, byte[] deriv |
| | 56 | 20 | | : base(clauseType, derivationNonce, derivationLength) |
| | | 21 | | { |
| | 56 | 22 | | if (identificationData == null) |
| | | 23 | | { |
| | 0 | 24 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(identificatio |
| | | 25 | | } |
| | 56 | 26 | | if (identificationData.Length == 0) |
| | | 27 | | { |
| | 0 | 28 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(identif |
| | | 29 | | } |
| | | 30 | | |
| | 56 | 31 | | if (cloneBuffer) |
| | | 32 | | { |
| | 6 | 33 | | _identificationData = SecurityUtils.CloneBuffer(identificationData); |
| | | 34 | | } |
| | | 35 | | else |
| | | 36 | | { |
| | 50 | 37 | | _identificationData = identificationData; |
| | | 38 | | } |
| | 50 | 39 | | } |
| | | 40 | | |
| | | 41 | | public byte[] GetBuffer() |
| | | 42 | | { |
| | 0 | 43 | | return SecurityUtils.CloneBuffer(_identificationData); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | protected byte[] GetRawBuffer() |
| | | 47 | | { |
| | 0 | 48 | | return _identificationData; |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 52 | | { |
| | 0 | 53 | | BinaryKeyIdentifierClause that = keyIdentifierClause as BinaryKeyIdentifierClause; |
| | 0 | 54 | | return ReferenceEquals(this, that) || (that != null && that.Matches(_identificationData)); |
| | | 55 | | } |
| | | 56 | | |
| | | 57 | | public bool Matches(byte[] data) |
| | | 58 | | { |
| | 50 | 59 | | return Matches(data, 0); |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | public bool Matches(byte[] data, int offset) |
| | | 63 | | { |
| | 53 | 64 | | if (offset < 0) |
| | | 65 | | { |
| | 0 | 66 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset) |
| | | 67 | | } |
| | 53 | 68 | | return SecurityUtils.MatchesBuffer(_identificationData, 0, data, offset); |
| | | 69 | | } |
| | | 70 | | |
| | | 71 | | internal string ToBase64String() |
| | | 72 | | { |
| | 0 | 73 | | return Convert.ToBase64String(_identificationData); |
| | | 74 | | } |
| | | 75 | | |
| | | 76 | | internal string ToHexString() |
| | | 77 | | { |
| | 0 | 78 | | return new HexBinary(_identificationData).ToString(); |
| | | 79 | | } |
| | | 80 | | } |
| | | 81 | | } |