Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 5652339b authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

refactoring: move digestData class to separate file

parent 9874f983
No related branches found
No related tags found
No related merge requests found
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
namespace TUGraz.VectoCommon.InputData {
public class DigestData
{
private const string ReferenceElementXPath = ".//*[local-name()='Reference']";
private const string TransformElementXPath = ".//*[local-name()='Transform']";
private const string DigestMethodElementXPath = ".//*[local-name()='DigestMethod']";
private const string UriAttr = "URI";
private const string AlgorithmAttr = "Algorithm";
private const string ReferenceUriAttrXPath = ReferenceElementXPath + "/@" + UriAttr;
private const string TransformAlgorithmAttrXPath = TransformElementXPath + "/@" + AlgorithmAttr;
private const string DigestMethodAlgorithmAttrXPath = DigestMethodElementXPath + "/@" + AlgorithmAttr;
private const string DigestValueElementXPath = ".//*[local-name()='DigestValue']";
public DigestData(string reference, string[] c14n, string digestMethod, string digestValue)
{
Reference = reference;
CanonicalizationMethods = c14n;
DigestMethod = digestMethod;
DigestValue = digestValue;
}
public DigestData(XPathNavigator navigator)
{
Reference = navigator.SelectSingleNode(ReferenceUriAttrXPath)?.InnerXml;
var nodes = navigator.Select(TransformAlgorithmAttrXPath);
var c14n = new List<string>();
while (nodes.MoveNext()) {
c14n.Add(nodes.Current.InnerXml);
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = navigator.SelectSingleNode(DigestMethodAlgorithmAttrXPath)?.InnerXml;
DigestValue = navigator.SelectSingleNode(DigestValueElementXPath)?.InnerXml;
}
public DigestData(XmlNode xmlNode)
{
Reference = xmlNode.SelectSingleNode(ReferenceUriAttrXPath)?.InnerXml;
var nodes = xmlNode.SelectNodes(TransformAlgorithmAttrXPath);
var c14n = new List<string>();
if (nodes != null) {
for (var i = 0; i < nodes.Count; i++) {
c14n.Add(nodes[i].InnerXml);
}
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = xmlNode.SelectSingleNode(DigestMethodAlgorithmAttrXPath)?.InnerXml;
DigestValue = xmlNode.SelectSingleNode(DigestValueElementXPath)?.InnerXml;
}
public DigestData(XNode xmlNode)
{
Reference = xmlNode.XPathSelectElement(ReferenceElementXPath)?.Attribute(XName.Get(UriAttr))?.Value;
var nodes = xmlNode.XPathSelectElements(TransformElementXPath);
var c14n = new List<string>();
foreach (var node in nodes) {
c14n.Add(node.Attribute(XName.Get(AlgorithmAttr))?.Value);
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = xmlNode.XPathSelectElement(DigestMethodElementXPath)?.Attribute(XName.Get(AlgorithmAttr))?.Value;
DigestValue = xmlNode.XPathSelectElement(DigestValueElementXPath)?.Value;
}
public string DigestValue { get; }
public string Reference { get; }
public string[] CanonicalizationMethods { get; }
public string DigestMethod { get; }
}
}
\ No newline at end of file
......@@ -31,9 +31,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using TUGraz.VectoCommon.Hashing;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoHashing;
......@@ -75,71 +72,4 @@ namespace TUGraz.VectoCommon.InputData
DigestData JobDigest { get; }
}
public class DigestData
{
private const string ReferenceQueryXPath = ".//*[local-name()='Reference']/@URI";
private const string AlgorithmQueryXPath = ".//*[local-name()='Transform']/@Algorithm";
private const string DigestMethodQueryXPath = ".//*[local-name()='DigestMethod']/@Algorithm";
private const string DigestValueQuerXPath = ".//*[local-name()='DigestValue']";
public DigestData(string reference, string[] c14n, string digestMethod, string digestValue)
{
Reference = reference;
CanonicalizationMethods = c14n;
DigestMethod = digestMethod;
DigestValue = digestValue;
}
public DigestData(XPathNavigator navigator)
{
Reference = navigator.SelectSingleNode(ReferenceQueryXPath)?.InnerXml;
var nodes = navigator.Select(AlgorithmQueryXPath);
var c14n = new List<string>();
while (nodes.MoveNext()) {
c14n.Add(nodes.Current.InnerXml);
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = navigator.SelectSingleNode(DigestMethodQueryXPath)?.InnerXml;
DigestValue = navigator.SelectSingleNode(DigestValueQuerXPath)?.InnerXml;
}
public DigestData(XmlNode xmlNode)
{
Reference = xmlNode.SelectSingleNode(ReferenceQueryXPath)?.InnerXml;
var nodes = xmlNode.SelectNodes(AlgorithmQueryXPath);
var c14n = new List<string>();
if (nodes != null) {
for (var i = 0; i < nodes.Count; i++) {
c14n.Add(nodes[i].InnerXml);
}
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = xmlNode.SelectSingleNode(DigestMethodQueryXPath)?.InnerXml;
DigestValue = xmlNode.SelectSingleNode(DigestValueQuerXPath)?.InnerXml;
}
public DigestData(XElement xmlNode)
{
Reference = xmlNode.XPathSelectElement(".//*[local-name()='Reference']")?.Attribute(XName.Get("URI"))?.Value;
var nodes = xmlNode.XPathSelectElements(".//*[local-name()='Transform']");
var c14n = new List<string>();
foreach (var node in nodes) {
c14n.Add(node.Attribute(XName.Get("Algorithm"))?.Value);
}
CanonicalizationMethods = c14n.ToArray();
DigestMethod = xmlNode.XPathSelectElement(".//*[local-name()='DigestMethod']")?.Attribute(XName.Get("Algorithm"))?.Value;
DigestValue = xmlNode.XPathSelectElement(DigestValueQuerXPath)?.Value;
}
public string DigestValue { get; }
public string Reference { get; }
public string[] CanonicalizationMethods { get; }
public string DigestMethod { get; }
}
}
......@@ -53,6 +53,7 @@
<Compile Include="Hashing\IVectoHash.cs" />
<Compile Include="Hashing\VectoComponents.cs" />
<Compile Include="InputData\DataSourceType.cs" />
<Compile Include="InputData\DigestData.cs" />
<Compile Include="InputData\TableData.cs">
<SubType>Component</SubType>
</Compile>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment