| | | 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.Xml; |
| | | 5 | | |
| | | 6 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 7 | | { |
| | | 8 | | public class GenericXmlSecurityKeyIdentifierClause : SecurityKeyIdentifierClause |
| | | 9 | | { |
| | | 10 | | public GenericXmlSecurityKeyIdentifierClause(XmlElement referenceXml) |
| | 0 | 11 | | : this(referenceXml, null, 0) |
| | | 12 | | { |
| | 0 | 13 | | } |
| | | 14 | | |
| | | 15 | | public GenericXmlSecurityKeyIdentifierClause(XmlElement referenceXml, byte[] derivationNonce, int derivationLeng |
| | 0 | 16 | | : base(null, derivationNonce, derivationLength) |
| | | 17 | | { |
| | 0 | 18 | | ReferenceXml = referenceXml ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(refer |
| | 0 | 19 | | } |
| | | 20 | | |
| | 0 | 21 | | public XmlElement ReferenceXml { get; } |
| | | 22 | | |
| | | 23 | | public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) |
| | | 24 | | { |
| | 0 | 25 | | GenericXmlSecurityKeyIdentifierClause that = keyIdentifierClause as GenericXmlSecurityKeyIdentifierClause; |
| | 0 | 26 | | return ReferenceEquals(this, that) || (that != null && that.Matches(ReferenceXml)); |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | private bool Matches(XmlElement xmlElement) |
| | | 30 | | { |
| | 0 | 31 | | if (xmlElement == null) |
| | | 32 | | { |
| | 0 | 33 | | return false; |
| | | 34 | | } |
| | | 35 | | |
| | 0 | 36 | | return CompareNodes(ReferenceXml, xmlElement); |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | private bool CompareNodes(XmlNode originalNode, XmlNode newNode) |
| | | 40 | | { |
| | 0 | 41 | | if (originalNode.OuterXml == newNode.OuterXml) |
| | | 42 | | { |
| | 0 | 43 | | return true; |
| | | 44 | | } |
| | | 45 | | |
| | 0 | 46 | | if (originalNode.LocalName != newNode.LocalName || originalNode.InnerText != newNode.InnerText) |
| | | 47 | | { |
| | 0 | 48 | | return false; |
| | | 49 | | } |
| | | 50 | | |
| | 0 | 51 | | if (originalNode.InnerXml == newNode.InnerXml) |
| | | 52 | | { |
| | 0 | 53 | | return true; |
| | | 54 | | } |
| | | 55 | | |
| | 0 | 56 | | if (originalNode.HasChildNodes) |
| | | 57 | | { |
| | 0 | 58 | | if (!newNode.HasChildNodes || originalNode.ChildNodes.Count != newNode.ChildNodes.Count) |
| | | 59 | | { |
| | 0 | 60 | | return false; |
| | | 61 | | } |
| | | 62 | | |
| | 0 | 63 | | bool childrenStatus = true; |
| | 0 | 64 | | for (int i = 0; i < originalNode.ChildNodes.Count; i++) |
| | | 65 | | { |
| | 0 | 66 | | childrenStatus = childrenStatus & CompareNodes(originalNode.ChildNodes[i], newNode.ChildNodes[i]); |
| | | 67 | | } |
| | | 68 | | |
| | 0 | 69 | | return childrenStatus; |
| | | 70 | | } |
| | 0 | 71 | | else if (newNode.HasChildNodes) |
| | | 72 | | { |
| | 0 | 73 | | return false; |
| | | 74 | | } |
| | | 75 | | |
| | 0 | 76 | | return true; |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | } |