internal void HashElement(HashAlgorithm ha, string localName, string prefix, string ns) { ha.AddString(1.ToString() + "\0x01" + (this._bIgnoreNamespaces || this._bIgnorePrefixes ? (object)string.Empty : (object)prefix) + "\0x01" + (this._bIgnoreNamespaces ? (object)string.Empty : (object)ns) + "\0x01" + localName); }
internal ulong HashAttribute(string localName, string prefix, string ns, string value) { return(HashAlgorithm.GetHash(2.ToString() + "\0x01" + (this._bIgnoreNamespaces || this._bIgnorePrefixes ? (object)string.Empty : (object)prefix) + "\0x01" + (this._bIgnoreNamespaces ? (object)string.Empty : (object)ns) + "\0x01" + localName + "\0x01" + value)); }
private ulong ComputeHashXmlNode(XmlNode node) { switch (node.NodeType) { case XmlNodeType.Element: var xmlElement = (XmlElement)node; var ha = new HashAlgorithm(); this.HashElement(ha, xmlElement.LocalName, xmlElement.Prefix, xmlElement.NamespaceURI); this.ComputeHashXmlChildren(ha, (XmlNode)xmlElement); return(ha.Hash); case XmlNodeType.Attribute: return(0); case XmlNodeType.Text: var xmlCharacterData1 = (XmlCharacterData)node; return(this._bIgnoreWhitespace ? this.HashCharacterNode(xmlCharacterData1.NodeType, XmlDiff.NormalizeText(xmlCharacterData1.Value)) : this.HashCharacterNode(xmlCharacterData1.NodeType, xmlCharacterData1.Value)); case XmlNodeType.CDATA: var xmlCharacterData2 = (XmlCharacterData)node; return(this.HashCharacterNode(xmlCharacterData2.NodeType, xmlCharacterData2.Value)); case XmlNodeType.EntityReference: return(this.HashER(node.Name)); case XmlNodeType.ProcessingInstruction: if (this._bIgnorePI) { return(0); } var processingInstruction = (XmlProcessingInstruction)node; return(this.HashPI(processingInstruction.Target, processingInstruction.Value)); case XmlNodeType.Comment: return(!this._bIgnoreComments ? this.HashCharacterNode(XmlNodeType.Comment, node.Value) : 0UL); case XmlNodeType.DocumentType: if (this._bIgnoreDtd) { return(0); } var xmlDocumentType = (XmlDocumentType)node; return(this.HashDocumentType(xmlDocumentType.Name, xmlDocumentType.PublicId, xmlDocumentType.SystemId, xmlDocumentType.InternalSubset)); case XmlNodeType.DocumentFragment: return(0); case XmlNodeType.Whitespace: return(0); case XmlNodeType.SignificantWhitespace: if (this._bIgnoreWhitespace) { return(0); } goto case XmlNodeType.Text; case XmlNodeType.XmlDeclaration: return(this._bIgnoreXmlDecl ? 0UL : this.HashXmlDeclaration(XmlDiff.NormalizeXmlDeclaration(node.Value))); default: return(0); } }
private void HashDocument(HashAlgorithm ha) { }
internal ulong HashXmlDeclaration(string value) { return(HashAlgorithm.GetHash(17.ToString() + "\0x01" + value)); }
internal ulong ComputeHashXmlDiffElement( XmlDiffElement el ) { HashAlgorithm ha = new HashAlgorithm(); HashElement( ha, el.LocalName, el.Prefix, el.NamespaceURI ); ComputeHashXmlDiffAttributes( ha, el ); ComputeHashXmlDiffChildren( ha, el ); return ha.Hash; }
internal void HashElement( HashAlgorithm ha, string localName, string prefix, string ns ) { ha.AddString( (int)(XmlNodeType.Element) + Delimiter + ( ( _bIgnoreNamespaces || _bIgnorePrefixes ) ? string.Empty : prefix ) + Delimiter + ( _bIgnoreNamespaces ? string.Empty : ns ) + Delimiter + localName ); }
internal ulong HashPI(string target, string value) { return(HashAlgorithm.GetHash(7.ToString() + "\0x01" + target + "\0x01" + value)); }
private ulong ComputeHashXmlNode( XmlNode node ) { switch ( node.NodeType ) { case XmlNodeType.Element: { XmlElement el = (XmlElement)node; HashAlgorithm ha = new HashAlgorithm(); HashElement( ha, el.LocalName, el.Prefix, el.NamespaceURI ); ComputeHashXmlChildren( ha, el ); return ha.Hash; } case XmlNodeType.Attribute: // attributes are hashed in ComputeHashXmlChildren; Debug.Assert( false ); return 0; case XmlNodeType.Whitespace: return 0; case XmlNodeType.SignificantWhitespace: if ( !_bIgnoreWhitespace ) goto case XmlNodeType.Text; return 0; case XmlNodeType.Comment: if ( !_bIgnoreComments ) return HashCharacterNode( XmlNodeType.Comment, ((XmlCharacterData)node).Value ); return 0; case XmlNodeType.Text: { XmlCharacterData cd = (XmlCharacterData)node; if ( _bIgnoreWhitespace ) return HashCharacterNode( cd.NodeType, XmlDiff.NormalizeText( cd.Value ) ); else return HashCharacterNode( cd.NodeType, cd.Value ); } case XmlNodeType.CDATA: { XmlCharacterData cd = (XmlCharacterData)node; return HashCharacterNode( cd.NodeType, cd.Value ); } case XmlNodeType.ProcessingInstruction: { if ( _bIgnorePI ) return 0; XmlProcessingInstruction pi = (XmlProcessingInstruction)node; return HashPI( pi.Target, pi.Value ); } case XmlNodeType.EntityReference: { XmlEntityReference er = (XmlEntityReference)node; return HashER( er.Name ); } case XmlNodeType.XmlDeclaration: { if ( _bIgnoreXmlDecl ) return 0; XmlDeclaration decl = (XmlDeclaration)node; return HashXmlDeclaration( XmlDiff.NormalizeXmlDeclaration( decl.Value ) ); } case XmlNodeType.DocumentType: { if ( _bIgnoreDtd ) return 0; XmlDocumentType docType = (XmlDocumentType)node; return HashDocumentType( docType.Name, docType.PublicId, docType.SystemId, docType.InternalSubset ); } case XmlNodeType.DocumentFragment: return 0; default: Debug.Assert( false ); return 0; } }
private void HashDocument( HashAlgorithm ha ) { // Intentionally empty }
private void ComputeHashXmlChildren( HashAlgorithm ha, XmlNode parent ) { XmlElement el = parent as XmlElement; if ( el != null ) { ulong attrHashSum = 0; int attrsCount = 0; XmlAttributeCollection attrs = ((XmlElement)parent).Attributes; for ( int i = 0; i < attrs.Count; i++ ) { XmlAttribute attr = (XmlAttribute)attrs.Item(i); ulong hashValue = 0; // default namespace def if ( attr.LocalName == "xmlns" && attr.Prefix == string.Empty ) { if ( _bIgnoreNamespaces ) { continue; } hashValue = HashNamespace( string.Empty, attr.Value ); } // namespace def else if ( attr.Prefix == "xmlns" ) { if ( _bIgnoreNamespaces ) { continue; } hashValue = HashNamespace( attr.LocalName, attr.Value ); } // attribute else { if ( _bIgnoreWhitespace ) hashValue = HashAttribute( attr.LocalName, attr.Prefix, attr.NamespaceURI, XmlDiff.NormalizeText( attr.Value ) ); else hashValue = HashAttribute( attr.LocalName, attr.Prefix, attr.NamespaceURI, attr.Value ); } Debug.Assert( hashValue != 0 ); attrsCount++; attrHashSum += hashValue; } if ( attrsCount != 0 ) { ha.AddULong( attrHashSum ); ha.AddInt( attrsCount ); } } int childrenCount = 0; if ( _bIgnoreChildOrder ) { ulong totalHashSum = 0; XmlNode curChild = parent.FirstChild; while ( curChild != null ) { ulong hashValue = ComputeHashXmlNode( curChild ); if ( hashValue != 0 ) { totalHashSum += hashValue; childrenCount++; } curChild = curChild.NextSibling; } ha.AddULong( totalHashSum ); } else { XmlNode curChild = parent.FirstChild; while ( curChild != null ) { ulong hashValue = ComputeHashXmlNode( curChild ); if ( hashValue != 0 ) { ha.AddULong( hashValue ); childrenCount++; } curChild = curChild.NextSibling; } } if ( childrenCount != 0 ) ha.AddInt( childrenCount ); }
private void ComputeHashXmlDiffChildren( HashAlgorithm ha, XmlDiffParentNode parent ) { int childrenCount = 0; if ( _bIgnoreChildOrder ) { ulong totalHash = 0; XmlDiffNode curChild = parent.FirstChildNode; while ( curChild != null ) { Debug.Assert( !( curChild is XmlDiffAttributeOrNamespace ) ); Debug.Assert ( curChild.HashValue != 0 ); totalHash += curChild.HashValue; childrenCount++; curChild = curChild._nextSibling; } ha.AddULong( totalHash ); } else { XmlDiffNode curChild = parent.FirstChildNode; while ( curChild != null ) { Debug.Assert( !( curChild is XmlDiffAttributeOrNamespace ) ); Debug.Assert ( curChild.HashValue != 0 ); ha.AddULong( curChild.HashValue ); childrenCount++; curChild = curChild._nextSibling; } } if ( childrenCount != 0 ) ha.AddInt( childrenCount ); }
private void ComputeHashXmlDiffAttributes( HashAlgorithm ha, XmlDiffElement el ) { int attrCount = 0; ulong attrHashAll = 0; XmlDiffAttributeOrNamespace curAttrOrNs = el._attributes; while ( curAttrOrNs != null ) { attrHashAll += curAttrOrNs.HashValue; attrCount++; curAttrOrNs = (XmlDiffAttributeOrNamespace)curAttrOrNs._nextSibling; } if ( attrCount > 0 ) { ha.AddULong( attrHashAll ); ha.AddInt( attrCount ); } }
internal ulong HashNamespace(string prefix, string ns) { return(HashAlgorithm.GetHash(100.ToString() + "\0x01" + (this._bIgnorePrefixes ? (object)string.Empty : (object)prefix) + "\0x01" + ns)); }
private ulong ComputeHashXmlDocument( XmlDocument doc ) { HashAlgorithm ha = new HashAlgorithm(); HashDocument( ha ); ComputeHashXmlChildren( ha, doc ); return ha.Hash; }
internal ulong HashCharacterNode(XmlNodeType nodeType, string value) { return(HashAlgorithm.GetHash(((int)nodeType).ToString() + "\0x01" + value)); }
private ulong ComputeHashXmlFragment( XmlDocumentFragment frag ) { HashAlgorithm ha = new HashAlgorithm(); ComputeHashXmlChildren( ha, frag ); return ha.Hash; }
internal ulong HashER(string name) { return(HashAlgorithm.GetHash(5.ToString() + "\0x01" + name)); }
private void ComputeHashXmlChildren(HashAlgorithm ha, XmlNode parent) { if (parent is XmlElement) { ulong u = 0; var i = 0; var attributes = parent.Attributes; for (var index = 0; index < attributes.Count; ++index) { var xmlAttribute = (XmlAttribute)attributes.Item(index); ulong num; if (xmlAttribute.LocalName == "xmlns" && xmlAttribute.Prefix == string.Empty) { if (!this._bIgnoreNamespaces) { num = this.HashNamespace(string.Empty, xmlAttribute.Value); } else { continue; } } else if (xmlAttribute.Prefix == "xmlns") { if (!this._bIgnoreNamespaces) { num = this.HashNamespace(xmlAttribute.LocalName, xmlAttribute.Value); } else { continue; } } else { num = !this._bIgnoreWhitespace ? this.HashAttribute(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI, xmlAttribute.Value) : this.HashAttribute(xmlAttribute.LocalName, xmlAttribute.Prefix, xmlAttribute.NamespaceURI, XmlDiff.NormalizeText(xmlAttribute.Value)); } ++i; u += num; } if (i != 0) { ha.AddULong(u); ha.AddInt(i); } } var i1 = 0; if (this._bIgnoreChildOrder) { ulong u = 0; for (var node = parent.FirstChild; node != null; node = node.NextSibling) { var hashXmlNode = this.ComputeHashXmlNode(node); if (hashXmlNode != 0UL) { u += hashXmlNode; ++i1; } } ha.AddULong(u); } else { for (var node = parent.FirstChild; node != null; node = node.NextSibling) { var hashXmlNode = this.ComputeHashXmlNode(node); if (hashXmlNode != 0UL) { ha.AddULong(hashXmlNode); ++i1; } } } if (i1 == 0) { return; } ha.AddInt(i1); }
internal ulong HashDocumentType(string name, string publicId, string systemId, string subset) { return(HashAlgorithm.GetHash(10.ToString() + "\0x01" + name + "\0x01" + publicId + "\0x01" + systemId + "\0x01" + subset)); }
internal ulong ComputeHashXmlDiffDocument( XmlDiffDocument doc ) { HashAlgorithm ha = new HashAlgorithm(); HashDocument( ha ); ComputeHashXmlDiffChildren( ha, doc ); return ha.Hash; }