Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit b2821d0e authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

refacotring modelviews to use base class from report validation, more...

refacotring modelviews to use base class from report validation, more expressive icons for validating input
parent 218dedab
No related branches found
No related tags found
No related merge requests found
Showing
with 380 additions and 244 deletions
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Icon_XML_unknown.xaml" /> <ResourceDictionary Source="Resources/Icon_XML_outline.xaml" />
<ResourceDictionary Source="Resources/Icon_XML_OK.xaml" /> <ResourceDictionary Source="Resources/Icon_XML_red.xaml" />
<ResourceDictionary Source="Resources/Icon_XML_NOK.xaml" /> <ResourceDictionary Source="Resources/Icon_XML_green1.xaml" />
<ResourceDictionary Source="Resources/Icon_XML_green2.xaml" />
<ResourceDictionary Source="Resources/Icon_XML_green.xaml" />
<ResourceDictionary Source="Resources/Icon_OK.xaml" /> <ResourceDictionary Source="Resources/Icon_OK.xaml" />
<ResourceDictionary Source="Resources/Icon_NOK.xaml" /> <ResourceDictionary Source="Resources/Icon_NOK.xaml" />
<ResourceDictionary Source="Resources/UserInterfaceResources.xaml" /> <ResourceDictionary Source="Resources/UserInterfaceResources.xaml" />
......
...@@ -129,15 +129,23 @@ ...@@ -129,15 +129,23 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Resources\Icon_XML_NOK.xaml"> <Page Include="Resources\Icon_XML_green2.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\Icon_XML_green1.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\Icon_XML_red.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Resources\Icon_XML_OK.xaml"> <Page Include="Resources\Icon_XML_green.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Resources\Icon_XML_unknown.xaml"> <Page Include="Resources\Icon_XML_outline.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
......
...@@ -12,7 +12,7 @@ namespace HashingTool.Helper ...@@ -12,7 +12,7 @@ namespace HashingTool.Helper
{ {
var val = value as ICollection; var val = value as ICollection;
if (val == null) { if (val == null) {
throw new ArgumentException("can only convert collections!"); return null;
} }
if (targetType == typeof(object) || targetType == typeof(string)) { if (targetType == typeof(object) || targetType == typeof(string)) {
var tmp = new string[val.Count]; var tmp = new string[val.Count];
...@@ -20,7 +20,7 @@ namespace HashingTool.Helper ...@@ -20,7 +20,7 @@ namespace HashingTool.Helper
foreach (var entry in val) { foreach (var entry in val) {
tmp[i++] = entry.ToString(); tmp[i++] = entry.ToString();
} }
return string.Join(", ", tmp); return string.Join("; ", tmp);
} }
throw new ArgumentException("Unhandled target type"); throw new ArgumentException("Unhandled target type");
} }
......
...@@ -90,6 +90,11 @@ namespace HashingTool.Helper ...@@ -90,6 +90,11 @@ namespace HashingTool.Helper
try { try {
var h = VectoHash.Load(xml); var h = VectoHash.Load(xml);
xmlViewModel.DigestValueComputed = h.ComputeHash(); xmlViewModel.DigestValueComputed = h.ComputeHash();
xmlViewModel.DigestMethod = h.GetDigestMethod();
var c14N = h.GetCanonicalizationMethods().ToArray();
foreach (var c in c14N) {
xmlViewModel.CanonicalizationMethods.Add(c);
}
} catch (Exception e) { } catch (Exception e) {
xmlViewModel.XMLFile.XMLValidationErrors.Add(e.Message); xmlViewModel.XMLFile.XMLValidationErrors.Add(e.Message);
xmlViewModel.DigestValueComputed = ""; xmlViewModel.DigestValueComputed = "";
...@@ -104,6 +109,11 @@ namespace HashingTool.Helper ...@@ -104,6 +109,11 @@ namespace HashingTool.Helper
} }
try { try {
var h = VectoHash.Load(xml); var h = VectoHash.Load(xml);
report.DigestMethod = h.GetDigestMethod();
var c14N = h.GetCanonicalizationMethods().ToArray();
foreach (var c in c14N) {
report.CanonicalizationMethods.Add(c);
}
try { try {
report.DigestValueRead = h.ReadHash(); report.DigestValueRead = h.ReadHash();
} catch { } catch {
......
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Icon_XML_OK">
<Canvas>
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Icon_XML_green">
<Canvas>
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Icon_XML_green1">
<Canvas>
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Icon_XML_green2">
<Canvas>
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" Fill="#FF00C000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" Fill="#FFFF0000" StrokeThickness="1" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="ICON_XML_outline">
<Canvas Name="layer1">
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="Icon_XML_NOK"> <DataTemplate x:Key="Icon_XML_red">
<Canvas> <Canvas>
<Canvas.RenderTransform> <Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" /> <TranslateTransform X="-59.285156" Y="-215.2361" />
......
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="ICON_XML_unknown">
<Canvas Name="layer1">
<Canvas.RenderTransform>
<TranslateTransform X="-59.285156" Y="-215.2361" />
</Canvas.RenderTransform>
<Canvas Name="flowRoot4136" Opacity="1">
<Path Name="path4145" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 59.285156 243.86892 9.785156 -14.94141 -8.867187 -13.69141 6.757812 0 5.742188 9.19922 5.625 -9.19922 6.699219 0 -8.90625 13.90625 9.785156 14.72657 -6.972656 0 -6.347657 -9.90235 -6.367187 9.90235 -6.933594 0 z" />
<Path Name="path4147" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 88.835937 243.86892 0 -28.63282 8.652344 0 5.195309 19.53125 5.13672 -19.53125 8.67188 0 0 28.63282 -5.3711 0 0 -22.53907 -5.68359 22.53907 -5.566406 0 -5.664063 -22.53907 0 22.53907 -5.371094 0 z" />
<Path Name="path4149" StrokeThickness="1" Stroke="#FF464646" StrokeLineJoin="Miter" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat"
Data="m 122.42969 243.86892 0 -28.39844 5.78125 0 0 23.57422 14.375 0 0 4.82422 -20.15625 0 z" />
</Canvas>
</Canvas>
</DataTemplate>
</ResourceDictionary>
\ No newline at end of file
...@@ -6,6 +6,7 @@ namespace HashingTool.ViewModel ...@@ -6,6 +6,7 @@ namespace HashingTool.ViewModel
public string DigestValueRead { get; set; } public string DigestValueRead { get; set; }
public string DigestValueComputed { get; set; } public string DigestValueComputed { get; set; }
public string[] CanonicalizationMethod { get; set; } public string[] CanonicalizationMethod { get; set; }
public string DigestMethod { get; set; }
public bool Valid { get; set; } public bool Valid { get; set; }
} }
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
...@@ -12,56 +13,36 @@ using HashingTool.Helper; ...@@ -12,56 +13,36 @@ using HashingTool.Helper;
using HashingTool.Util; using HashingTool.Util;
using HashingTool.ViewModel.UserControl; using HashingTool.ViewModel.UserControl;
using TUGraz.VectoHashing; using TUGraz.VectoHashing;
using TUGraz.VectoHashing.Impl;
namespace HashingTool.ViewModel namespace HashingTool.ViewModel
{ {
public class HashComponentDataViewModel : ObservableObject, IMainView public class HashComponentDataViewModel : VectoXMLFile, IMainView
{ {
private string _digestValue; private string _digestValue;
private XDocument _result; private XDocument _result;
private readonly RelayCommand _saveCommand; private readonly RelayCommand _saveCommand;
private bool _busy;
private readonly XMLFile _sourceFile;
private bool? _componentDataValid; private bool? _componentDataValid;
private bool _busy;
public HashComponentDataViewModel() public HashComponentDataViewModel()
: base("Hash Component Data", false, HashingHelper.IsComponentFile)
{ {
XMLValidationErrors = new ObservableCollection<string>(); _xmlFile.PropertyChanged += SourceChanged;
_sourceFile = new XMLFile(IoService, false, HashingHelper.IsComponentFile);
_sourceFile.PropertyChanged += SourceChanged;
_saveCommand = new RelayCommand(SaveDocument, _saveCommand = new RelayCommand(SaveDocument,
() => !_busy && ComponentDataValid != null && ComponentDataValid.Value && _result != null); () => !_busy && ComponentDataValid != null && ComponentDataValid.Value && _result != null);
_busy = false;
// TODO!
CanonicalizaitionMethods = new ObservableCollection<string>() {
"urn:vecto:xml:2017:canonicalization",
"http://www.w3.org/2001/10/xml-exc-c14n#"
};
} }
public string Name
{
get { return "Hash Component Data"; }
}
public ICommand ShowHomeViewCommand public ICommand ShowHomeViewCommand
{ {
get { return ApplicationViewModel.HomeView; } get { return ApplicationViewModel.HomeView; }
} }
public XMLFile ComponentFile
{
get { return _sourceFile; }
}
public ObservableCollection<string> XMLValidationErrors { get; set; }
public string DigestValue public string DigestValue
{ {
get { return _digestValue; } get { return _digestValue; }
...@@ -81,10 +62,9 @@ namespace HashingTool.ViewModel ...@@ -81,10 +62,9 @@ namespace HashingTool.ViewModel
private void SourceChanged(object sender, PropertyChangedEventArgs e) private void SourceChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "Document") { if (e.PropertyName == "Document" || e.PropertyName == "IsValid")
DoComputeHash(); DoComputeHash();
} }
}
private void SaveDocument() private void SaveDocument()
{ {
...@@ -115,22 +95,27 @@ namespace HashingTool.ViewModel ...@@ -115,22 +95,27 @@ namespace HashingTool.ViewModel
} }
} }
public ObservableCollection<string> CanonicalizaitionMethods { get; private set; }
private async void DoComputeHash() private async void DoComputeHash()
{ {
if (_sourceFile.Document == null) { if (_busy) {
return;
}
if (_xmlFile.Document == null || _xmlFile.IsValid != XmlFileStatus.ValidXML) {
ComponentDataValid = false; ComponentDataValid = false;
DigestValue = ""; DigestValue = "";
DigestMethod = "";
CanonicalizationMethods.Clear();
return; return;
} }
try { try {
_busy = true; _busy = true;
ComponentDataValid = false; ComponentDataValid = false;
DigestValue = ""; DigestValue = "";
XMLValidationErrors.Clear(); _xmlFile.XMLValidationErrors.Clear();
CanonicalizationMethods.Clear();
var h = VectoHash.Load(_sourceFile.Document); var h = VectoHash.Load(_xmlFile.Document);
_result = h.AddHash(); _result = h.AddHash();
...@@ -145,7 +130,7 @@ namespace HashingTool.ViewModel ...@@ -145,7 +130,7 @@ namespace HashingTool.ViewModel
ComponentDataValid = true; ComponentDataValid = true;
var validator = new XMLValidator(r => { ComponentDataValid = r; }, var validator = new XMLValidator(r => { ComponentDataValid = r; },
(s, e) => { (s, e) => {
Application.Current.Dispatcher.Invoke(() => XMLValidationErrors.Add( Application.Current.Dispatcher.Invoke(() => _xmlFile.XMLValidationErrors.Add(
string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR", string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR",
e.ValidationEventArgs == null e.ValidationEventArgs == null
? e.Exception.Message + ? e.Exception.Message +
...@@ -156,15 +141,35 @@ namespace HashingTool.ViewModel ...@@ -156,15 +141,35 @@ namespace HashingTool.ViewModel
await validator.ValidateXML(XmlReader.Create(ms)); await validator.ValidateXML(XmlReader.Create(ms));
} }
if (ComponentDataValid != null && ComponentDataValid.Value) { if (ComponentDataValid != null && ComponentDataValid.Value) {
DigestValue = h.ComputeHash(); //var c14N = XMLHashProvider.DefaultCanonicalizationMethod.ToArray();
//var digestMethod = XMLHashProvider.DefaultDigestMethod;
//DigestValue = h.ComputeHash(c14N, digestMethod);
using (MemoryStream ms = new MemoryStream()) {
using (XmlWriter xw = XmlWriter.Create(ms, new XmlWriterSettings { Indent = true })) {
_result.WriteTo(xw);
xw.Flush();
}
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
var h2 = VectoHash.Load(ms);
var c14N = h2.GetCanonicalizationMethods().ToArray();
var digestMethod = h2.GetDigestMethod();
DigestValue = h.ReadHash();
foreach (var c in c14N) {
CanonicalizationMethods.Add(c);
}
RaisePropertyChanged("CanonicalizationMethods");
DigestMethod = digestMethod;
}
} }
_saveCommand.RaiseCanExecuteChanged();
} catch (Exception e) { } catch (Exception e) {
ComponentDataValid = false; ComponentDataValid = false;
DigestValue = ""; DigestValue = "";
XMLValidationErrors.Add(e.Message); _xmlFile.XMLValidationErrors.Add(e.Message);
CanonicalizationMethods.Clear();
} finally { } finally {
_busy = false; _busy = false;
_saveCommand.RaiseCanExecuteChanged();
} }
} }
} }
......
...@@ -13,35 +13,31 @@ namespace HashingTool.ViewModel ...@@ -13,35 +13,31 @@ namespace HashingTool.ViewModel
{ {
protected readonly XMLFile _xmlFile; protected readonly XMLFile _xmlFile;
protected string _manufacturerDigestComputed; protected string _digestValueComputed;
protected bool? _valid; protected bool? _valid;
protected string _name; protected string _name;
protected string _tooltip; protected string _tooltip;
protected readonly Func<XmlDocument, Collection<string>, bool?> _contentCheck;
protected string _componentType; protected string _componentType;
protected readonly Action<XmlDocument, VectoXMLFile> _validateHashes; protected readonly Action<XmlDocument, VectoXMLFile> _validateHashes;
private string _digestMethod;
public VectoXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, public VectoXMLFile(string name, bool validate, Func<XmlDocument, Collection<string>, bool?> contentCheck,
Action<XmlDocument, VectoXMLFile> hashValidation = null) Action<XmlDocument, VectoXMLFile> hashValidation = null)
{ {
_validateHashes = hashValidation; _validateHashes = hashValidation;
_xmlFile = new XMLFile(IoService, true, contentCheck); _xmlFile = new XMLFile(IoService, validate, contentCheck);
_xmlFile.PropertyChanged += FileChanged; _xmlFile.PropertyChanged += FileChanged;
Name = name; Name = name;
CanonicalizationMethods = new ObservableCollection<string>();
// TODO
CanonicalizationMethods = new[] {
"urn:vecto:xml:2017:canonicalization",
"http://www.w3.org/2001/10/xml-exc-c14n#"
};
Valid = null; Valid = null;
ValidTooltip = HashingHelper.ToolTipNone; ValidTooltip = HashingHelper.ToolTipNone;
} }
protected virtual void FileChanged(object sender, PropertyChangedEventArgs e) protected virtual void FileChanged(object sender, PropertyChangedEventArgs e)
{ {
if (_xmlFile.IsValid != null && XMLFile.IsValid.HasValue && _xmlFile.IsValid.Value) { if (_xmlFile.IsValid == XmlFileStatus.ValidXML) {
if (_xmlFile.HasContentValidation) { if (_xmlFile.HasContentValidation) {
Valid = _xmlFile.ContentValid; Valid = _xmlFile.ContentValid;
if (Valid != null && Valid.Value) { if (Valid != null && Valid.Value) {
...@@ -80,17 +76,29 @@ namespace HashingTool.ViewModel ...@@ -80,17 +76,29 @@ namespace HashingTool.ViewModel
} }
} }
public string[] CanonicalizationMethods { get; private set; } public ObservableCollection<string> CanonicalizationMethods { get; private set; }
public string DigestMethod
{
get { return _digestMethod; }
set {
if (_digestMethod == value) {
return;
}
_digestMethod = value;
RaisePropertyChanged("DigestMethod");
}
}
public string DigestValueComputed public string DigestValueComputed
{ {
get { return _manufacturerDigestComputed; } get { return _digestValueComputed; }
internal set { internal set {
if (_manufacturerDigestComputed == value) { if (_digestValueComputed == value) {
return; return;
} }
_manufacturerDigestComputed = value; _digestValueComputed = value;
RaisePropertyChanged("DigestValueComputed"); RaisePropertyChanged("DigestValueComputed");
} }
} }
...@@ -135,19 +143,19 @@ namespace HashingTool.ViewModel ...@@ -135,19 +143,19 @@ namespace HashingTool.ViewModel
public class HashedXMLFile : VectoXMLFile public class HashedXMLFile : VectoXMLFile
{ {
protected string _manufacturerDigestRead; protected string _digestValueRead;
public HashedXMLFile(IOService ioService, string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, public HashedXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck,
Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation) {} Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation) {}
public string DigestValueRead public string DigestValueRead
{ {
get { return _manufacturerDigestRead; } get { return _digestValueRead; }
internal set { internal set {
if (_manufacturerDigestRead == value) { if (_digestValueRead == value) {
return; return;
} }
_manufacturerDigestRead = value; _digestValueRead = value;
RaisePropertyChanged("DigestValueRead"); RaisePropertyChanged("DigestValueRead");
} }
} }
...@@ -155,11 +163,13 @@ namespace HashingTool.ViewModel ...@@ -155,11 +163,13 @@ namespace HashingTool.ViewModel
public class ReportXMLFile : HashedXMLFile public class ReportXMLFile : HashedXMLFile
{ {
private string _jobDigestRead; private string _jobDigestValueRead;
private string _jobDigestMethod;
private string[] _jobCanonicalizationMethod;
public ReportXMLFile(IOService ioService, string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, public ReportXMLFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck,
Action<XmlDocument, VectoXMLFile> hashValidation = null) Action<XmlDocument, VectoXMLFile> hashValidation = null)
: base(ioService, name, contentCheck, hashValidation) : base(name, contentCheck, hashValidation)
{ {
_xmlFile.PropertyChanged += ReadJobDigest; _xmlFile.PropertyChanged += ReadJobDigest;
} }
...@@ -167,28 +177,69 @@ namespace HashingTool.ViewModel ...@@ -167,28 +177,69 @@ namespace HashingTool.ViewModel
private void ReadJobDigest(object sender, PropertyChangedEventArgs e) private void ReadJobDigest(object sender, PropertyChangedEventArgs e)
{ {
var jobDigest = ""; var jobDigest = "";
var jobDigestMethod = "";
var jobc14NMethod = new string[] { };
if (e.PropertyName != "Document") { if (e.PropertyName != "Document") {
return; return;
} }
if (_xmlFile.Document != null && _xmlFile.Document.DocumentElement != null) { if (_xmlFile.Document != null && _xmlFile.Document.DocumentElement != null) {
var node = var digestValueNode =
_xmlFile.Document.SelectSingleNode("//*[local-name()='InputDataSignature']//*[local-name()='DigestValue']"); _xmlFile.Document.SelectSingleNode("//*[local-name()='InputDataSignature']//*[local-name()='DigestValue']");
if (node != null) { if (digestValueNode != null) {
jobDigest = node.InnerText; jobDigest = digestValueNode.InnerText;
}
var digestMethodNode =
_xmlFile.Document.SelectSingleNode(
"//*[local-name()='InputDataSignature']//*[local-name()='DigestMethod']/@Algorithm");
if (digestMethodNode != null) {
jobDigestMethod = digestMethodNode.InnerText;
}
var c14NtMethodNodes =
_xmlFile.Document.SelectNodes("//*[local-name()='InputDataSignature']//*[local-name()='Transform']/@Algorithm");
if (c14NtMethodNodes != null) {
jobc14NMethod = (from XmlNode node in c14NtMethodNodes select node.InnerText).ToArray();
}
}
JobCanonicalizationMethod = jobc14NMethod;
JobDigestMethod = jobDigestMethod;
JobDigestValue = jobDigest;
}
public string JobDigestMethod
{
get { return _jobDigestMethod; }
set {
if (_jobDigestMethod == value) {
return;
}
_jobDigestMethod = value;
RaisePropertyChanged("JobDigestMethod");
}
}
public string[] JobCanonicalizationMethod
{
get { return _jobCanonicalizationMethod; }
set {
if (_jobCanonicalizationMethod == value) {
return;
} }
_jobCanonicalizationMethod = value;
RaisePropertyChanged("JobCanonicalizationMethod");
} }
JobDigest = jobDigest;
} }
public string JobDigest public string JobDigestValue
{ {
get { return _jobDigestRead; } get { return _jobDigestValueRead; }
internal set { internal set {
if (_jobDigestRead == value) { if (_jobDigestValueRead == value) {
return; return;
} }
_jobDigestRead = value; _jobDigestValueRead = value;
RaisePropertyChanged("JobDigest"); RaisePropertyChanged("JobDigestValue");
} }
} }
} }
...@@ -200,7 +251,7 @@ namespace HashingTool.ViewModel ...@@ -200,7 +251,7 @@ namespace HashingTool.ViewModel
public VectoJobFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck, public VectoJobFile(string name, Func<XmlDocument, Collection<string>, bool?> contentCheck,
Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, contentCheck, hashValidation) Action<XmlDocument, VectoXMLFile> hashValidation = null) : base(name, true, contentCheck, hashValidation)
{ {
_xmlFile.PropertyChanged += JobFilechanged; _xmlFile.PropertyChanged += JobFilechanged;
Components = new ObservableCollection<ComponentEntry>(); Components = new ObservableCollection<ComponentEntry>();
...@@ -240,9 +291,12 @@ namespace HashingTool.ViewModel ...@@ -240,9 +291,12 @@ namespace HashingTool.ViewModel
private void DoValidateHash() private void DoValidateHash()
{ {
if (_xmlFile.Document == null || _xmlFile.ContentValid == null || !_xmlFile.ContentValid.Value) { if (_xmlFile.Document == null || _xmlFile.IsValid != XmlFileStatus.ValidXML || _xmlFile.ContentValid == null ||
!_xmlFile.ContentValid.Value) {
Components.Clear(); Components.Clear();
DigestValueComputed = ""; DigestValueComputed = "";
DigestMethod = "";
CanonicalizationMethods.Clear();
JobDataValid = false; JobDataValid = false;
return; return;
} }
...@@ -263,15 +317,14 @@ namespace HashingTool.ViewModel ...@@ -263,15 +317,14 @@ namespace HashingTool.ViewModel
? component.Entry.XMLElementName() ? component.Entry.XMLElementName()
: string.Format("{0} ({1})", component.Entry.XMLElementName(), i + 1); : string.Format("{0} ({1})", component.Entry.XMLElementName(), i + 1);
entry.Valid = h.ValidateHash(component.Entry, i); entry.Valid = h.ValidateHash(component.Entry, i);
entry.CanonicalizationMethod = new[] { entry.CanonicalizationMethod = h.GetCanonicalizationMethods(component.Entry, i).ToArray();
"urn:vecto:xml:2017:canonicalization", entry.DigestMethod = h.GetDigestMethod(component.Entry, i);
"http://www.w3.org/2001/10/xml-exc-c14n#"
};
entry.DigestValueRead = h.ReadHash(component.Entry, i); entry.DigestValueRead = h.ReadHash(component.Entry, i);
entry.DigestValueComputed = h.ComputeHash(component.Entry, i); entry.DigestValueComputed = h.ComputeHash(component.Entry, i);
if (!entry.Valid) { if (!entry.Valid) {
_xmlFile.XMLValidationErrors.Add( _xmlFile.XMLValidationErrors.Add(
string.Format("Digest Value mismatch for component \"{0}\". Read digest value: \"{1}\", computed digest value \"{2}\"", string.Format(
"Digest Value mismatch for component \"{0}\". Read digest value: \"{1}\", computed digest value \"{2}\"",
entry.Component, entry.DigestValueRead, entry.DigestValueComputed)); entry.Component, entry.DigestValueRead, entry.DigestValueComputed));
} }
Components.Add(entry); Components.Add(entry);
......
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
...@@ -11,10 +12,19 @@ using HashingTool.Util; ...@@ -11,10 +12,19 @@ using HashingTool.Util;
namespace HashingTool.ViewModel.UserControl namespace HashingTool.ViewModel.UserControl
{ {
public enum XmlFileStatus
{
Unknown, // no file selected, outline
Invalid, // reading failed, no xml, etc. red
InvalidXML, // does not validate against known schemas
IncorrectContent, // content validation failed
ValidXML // green
}
public class XMLFile : ObservableObject public class XMLFile : ObservableObject
{ {
private string _source; private string _source;
private bool? _isValid; private XmlFileStatus _isValid;
private bool _busy; private bool _busy;
...@@ -22,12 +32,14 @@ namespace HashingTool.ViewModel.UserControl ...@@ -22,12 +32,14 @@ namespace HashingTool.ViewModel.UserControl
private XmlDocument _document; private XmlDocument _document;
private readonly Func<XmlDocument, Collection<string>, bool?> _postVerification; private readonly Func<XmlDocument, Collection<string>, bool?> _postVerification;
private bool? _contentValid; private bool? _contentValid;
private RelayCommand _browseFileCommand;
public XMLFile(IOService ioservice, bool validate = false, public XMLFile(IOService ioservice, bool validate = false,
Func<XmlDocument, Collection<string>, bool?> contentCheck = null) Func<XmlDocument, Collection<string>, bool?> contentCheck = null)
{ {
IoService = ioservice; IoService = ioservice;
_validate = validate; _validate = validate;
_browseFileCommand = new RelayCommand(BrowseXMLFile, () => !_busy);
XMLValidationErrors = new ObservableCollection<string>(); XMLValidationErrors = new ObservableCollection<string>();
HasContentValidation = contentCheck != null; HasContentValidation = contentCheck != null;
_postVerification = contentCheck ?? ((x, c) => null); _postVerification = contentCheck ?? ((x, c) => null);
...@@ -66,7 +78,7 @@ namespace HashingTool.ViewModel.UserControl ...@@ -66,7 +78,7 @@ namespace HashingTool.ViewModel.UserControl
get { return _validate; } get { return _validate; }
} }
public bool? IsValid public XmlFileStatus IsValid
{ {
get { return _isValid; } get { return _isValid; }
private set { private set {
...@@ -75,14 +87,44 @@ namespace HashingTool.ViewModel.UserControl ...@@ -75,14 +87,44 @@ namespace HashingTool.ViewModel.UserControl
} }
_isValid = value; _isValid = value;
RaisePropertyChanged("IsValid"); RaisePropertyChanged("IsValid");
SetToolTip(value);
} }
} }
private void SetToolTip(XmlFileStatus value)
{
var toolTip = "";
switch (value) {
case XmlFileStatus.Unknown:
toolTip = "Select XML File file";
break;
case XmlFileStatus.Invalid:
toolTip = "Invalid file";
break;
case XmlFileStatus.InvalidXML:
toolTip = "XML Schema validation failed";
break;
case XmlFileStatus.IncorrectContent:
toolTip = "Incorrect XML content";
break;
case XmlFileStatus.ValidXML:
toolTip = "OK";
break;
}
if (ToolTip == toolTip) {
return;
}
ToolTip = toolTip;
RaisePropertyChanged("ToolTip");
}
public string ToolTip { get; internal set; }
public ObservableCollection<string> XMLValidationErrors { get; set; } public ObservableCollection<string> XMLValidationErrors { get; set; }
public ICommand BrowseFileCommand public ICommand BrowseFileCommand
{ {
get { return new RelayCommand(BrowseXMLFile, () => !_busy); } get { return _browseFileCommand; }
} }
public ICommand SetXMLFileCommnd public ICommand SetXMLFileCommnd
...@@ -96,7 +138,7 @@ namespace HashingTool.ViewModel.UserControl ...@@ -96,7 +138,7 @@ namespace HashingTool.ViewModel.UserControl
Document = null; Document = null;
XMLValidationErrors.Clear(); XMLValidationErrors.Clear();
ContentValid = null; ContentValid = null;
IsValid = null; IsValid = XmlFileStatus.Unknown;
return; return;
} }
using (var stream = File.OpenRead(fileName)) { using (var stream = File.OpenRead(fileName)) {
...@@ -122,24 +164,47 @@ namespace HashingTool.ViewModel.UserControl ...@@ -122,24 +164,47 @@ namespace HashingTool.ViewModel.UserControl
private async Task LoadXMLFile(Stream stream) private async Task LoadXMLFile(Stream stream)
{ {
_busy = true; _busy = true;
IsValid = null; IsValid = XmlFileStatus.Unknown;
ContentValid = null; ContentValid = null;
XMLValidationErrors.Clear(); XMLValidationErrors.Clear();
var fileValid = XmlFileStatus.ValidXML;
bool? contentValid = null;
if (_validate) { try {
var ms = new MemoryStream(); var ms = new MemoryStream();
if (_validate) {
// copy stream beforehand if validation is needed later on
await stream.CopyToAsync(ms); await stream.CopyToAsync(ms);
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
stream.Seek(0, SeekOrigin.Begin); stream.Seek(0, SeekOrigin.Begin);
Validate(XmlReader.Create(ms));
} }
var document = new XmlDocument(); var document = new XmlDocument();
var reader = XmlReader.Create(stream); var reader = XmlReader.Create(stream);
document.Load(reader); document.Load(reader);
Document = document; Document = document;
ContentValid = _postVerification(document, XMLValidationErrors); var xmlValid = true;
if (_validate) {
xmlValid = await Validate(XmlReader.Create(ms));
if (!xmlValid) {
fileValid = XmlFileStatus.InvalidXML;
}
}
if (HasContentValidation) {
contentValid = _postVerification(document, XMLValidationErrors);
if (xmlValid && (contentValid == null || !contentValid.Value)) {
fileValid = XmlFileStatus.IncorrectContent;
}
}
} catch (Exception e) {
XMLValidationErrors.Add(e.Message);
fileValid = XmlFileStatus.Invalid;
} finally {
IsValid = fileValid;
ContentValid = contentValid;
_busy = false; _busy = false;
_browseFileCommand.RaiseCanExecuteChanged();
}
} }
public bool HasContentValidation { get; private set; } public bool HasContentValidation { get; private set; }
...@@ -156,14 +221,16 @@ namespace HashingTool.ViewModel.UserControl ...@@ -156,14 +221,16 @@ namespace HashingTool.ViewModel.UserControl
} }
} }
private async void Validate(XmlReader xml) private async Task<bool> Validate(XmlReader xml)
{ {
var valid = true; var valid = true;
try { try {
var validator = new XMLValidator(r => { valid = r; }, var validator = new XMLValidator(r => { valid = r; },
(s, e) => { (s, e) => {
Application.Current.Dispatcher.Invoke(() => XMLValidationErrors.Add( Application.Current.Dispatcher.Invoke(
string.Format("Validation {0} Line {2}: {1}", s == XmlSeverityType.Warning ? "WARNING" : "ERROR", () =>
XMLValidationErrors.Add(string.Format("Validation {0} Line {2}: {1}",
s == XmlSeverityType.Warning ? "WARNING" : "ERROR",
e.ValidationEventArgs == null e.ValidationEventArgs == null
? e.Exception.Message + ? e.Exception.Message +
(e.Exception.InnerException != null ? Environment.NewLine + e.Exception.InnerException.Message : "") (e.Exception.InnerException != null ? Environment.NewLine + e.Exception.InnerException.Message : "")
...@@ -173,9 +240,8 @@ namespace HashingTool.ViewModel.UserControl ...@@ -173,9 +240,8 @@ namespace HashingTool.ViewModel.UserControl
await validator.ValidateXML(xml); await validator.ValidateXML(xml);
} catch (Exception e) { } catch (Exception e) {
XMLValidationErrors.Add(e.Message); XMLValidationErrors.Add(e.Message);
} finally {
IsValid = valid;
} }
return valid;
} }
} }
} }
using System; using System;
using System.Collections.ObjectModel;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using HashingTool.Helper; using HashingTool.Helper;
using HashingTool.ViewModel.UserControl;
using TUGraz.VectoHashing; using TUGraz.VectoHashing;
namespace HashingTool.ViewModel namespace HashingTool.ViewModel
{ {
public class VerifyComponentInputDataViewModel : ObservableObject, IMainView public class VerifyComponentInputDataViewModel : HashedXMLFile, IMainView
{ {
private string _digestValueComputed;
private string _digestValueRead;
private bool _componentDataValid; private bool _componentDataValid;
private string _componentType;
private readonly XMLFile _componentFile;
public VerifyComponentInputDataViewModel() public VerifyComponentInputDataViewModel()
: base("Verify Component Data", HashingHelper.IsComponentFile)
{ {
_componentFile = new XMLFile(IoService, true, HashingHelper.IsComponentFile); _xmlFile.PropertyChanged += ComponentFilechanged;
_componentFile.PropertyChanged += ComponentFilechanged;
// TODO!
CanonicalizaitionMethods = new ObservableCollection<string>() {
"urn:vecto:xml:2017:canonicalization",
"http://www.w3.org/2001/10/xml-exc-c14n#"
};
}
public string Name
{
get { return "Verify Component Data"; }
} }
public ICommand ShowHomeViewCommand public ICommand ShowHomeViewCommand
...@@ -42,48 +24,6 @@ namespace HashingTool.ViewModel ...@@ -42,48 +24,6 @@ namespace HashingTool.ViewModel
get { return ApplicationViewModel.HomeView; } get { return ApplicationViewModel.HomeView; }
} }
public XMLFile ComponentFile
{
get { return _componentFile; }
}
public string Component
{
get { return _componentType; }
set {
if (_componentType == value) {
return;
}
_componentType = value;
RaisePropertyChanged("Component");
}
}
public ObservableCollection<string> CanonicalizaitionMethods { get; private set; }
public string DigestValueComputed
{
get { return _digestValueComputed; }
set {
if (_digestValueComputed == value) {
return;
}
_digestValueComputed = value;
RaisePropertyChanged("DigestValueComputed");
}
}
public string DigestValueRead
{
get { return _digestValueRead; }
set {
if (_digestValueRead == value) {
return;
}
_digestValueRead = value;
RaisePropertyChanged("DigestValueRead");
}
}
public bool ComponentDataValid public bool ComponentDataValid
{ {
...@@ -99,14 +39,14 @@ namespace HashingTool.ViewModel ...@@ -99,14 +39,14 @@ namespace HashingTool.ViewModel
private void ComponentFilechanged(object sender, PropertyChangedEventArgs e) private void ComponentFilechanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == "Document") { if (e.PropertyName == "Document" || e.PropertyName == "ContentValid") {
DoValidateHash(); DoValidateHash();
} }
} }
private void DoValidateHash() private void DoValidateHash()
{ {
if (_componentFile.ContentValid == null || !_componentFile.ContentValid.Value || _componentFile.Document == null) { if (_xmlFile.ContentValid == null || !_xmlFile.ContentValid.Value || _xmlFile.Document == null) {
ComponentDataValid = false; ComponentDataValid = false;
DigestValueComputed = ""; DigestValueComputed = "";
DigestValueRead = ""; DigestValueRead = "";
...@@ -114,7 +54,7 @@ namespace HashingTool.ViewModel ...@@ -114,7 +54,7 @@ namespace HashingTool.ViewModel
return; return;
} }
try { try {
var h = VectoHash.Load(_componentFile.Document); var h = VectoHash.Load(_xmlFile.Document);
if (h.GetContainigComponents().Count != 1) { if (h.GetContainigComponents().Count != 1) {
IoService.Messagebox("Selected file is not a component file!", "Error reading XML File", MessageBoxButton.OK); IoService.Messagebox("Selected file is not a component file!", "Error reading XML File", MessageBoxButton.OK);
...@@ -125,12 +65,19 @@ namespace HashingTool.ViewModel ...@@ -125,12 +65,19 @@ namespace HashingTool.ViewModel
DigestValueRead = h.ReadHash(); DigestValueRead = h.ReadHash();
DigestValueComputed = h.ComputeHash(); DigestValueComputed = h.ComputeHash();
ComponentDataValid = h.ValidateHash(); ComponentDataValid = h.ValidateHash();
DigestMethod = h.GetDigestMethod();
CanonicalizationMethods.Clear();
foreach (var c in h.GetCanonicalizationMethods().ToArray()) {
CanonicalizationMethods.Add(c);
}
} catch (Exception e) { } catch (Exception e) {
ComponentDataValid = false; ComponentDataValid = false;
DigestValueComputed = ""; DigestValueComputed = "";
DigestValueRead = ""; DigestValueRead = "";
Component = ""; Component = "";
_componentFile.XMLValidationErrors.Add(e.Message); CanonicalizationMethods.Clear();
DigestMethod = "";
_xmlFile.XMLValidationErrors.Add(e.Message);
} }
} }
} }
......
using System; using System.Windows.Input;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Windows.Input;
using HashingTool.Helper; using HashingTool.Helper;
using HashingTool.ViewModel.UserControl; using HashingTool.ViewModel.UserControl;
using TUGraz.VectoHashing;
namespace HashingTool.ViewModel namespace HashingTool.ViewModel
{ {
......
...@@ -18,9 +18,9 @@ namespace HashingTool.ViewModel ...@@ -18,9 +18,9 @@ namespace HashingTool.ViewModel
public VerifyResultDataViewModel() public VerifyResultDataViewModel()
{ {
_jobFile = new VectoJobFile("Job File", HashingHelper.IsJobFile, HashingHelper.HashJobFile); _jobFile = new VectoJobFile("Job File", HashingHelper.IsJobFile, HashingHelper.HashJobFile);
_manufacturerReport = new ReportXMLFile(IoService, "Manufacturer Report", HashingHelper.IsManufacturerReport, _manufacturerReport = new ReportXMLFile("Manufacturer Report", HashingHelper.IsManufacturerReport,
HashingHelper.ValidateDocumentHash); HashingHelper.ValidateDocumentHash);
_customerReport = new ReportXMLFile(IoService, "Customer Report", HashingHelper.IsCustomerReport, _customerReport = new ReportXMLFile("Customer Report", HashingHelper.IsCustomerReport,
HashingHelper.ValidateDocumentHash); HashingHelper.ValidateDocumentHash);
Files = new ObservableCollection<VectoXMLFile> { _jobFile, _manufacturerReport, _customerReport }; Files = new ObservableCollection<VectoXMLFile> { _jobFile, _manufacturerReport, _customerReport };
...@@ -68,7 +68,7 @@ namespace HashingTool.ViewModel ...@@ -68,7 +68,7 @@ namespace HashingTool.ViewModel
{ {
get { get {
return _manufacturerReport.Valid != null && _manufacturerReport.Valid.Value && return _manufacturerReport.Valid != null && _manufacturerReport.Valid.Value &&
_manufacturerReport.JobDigest == _jobFile.DigestValueComputed; _manufacturerReport.JobDigestValue == _jobFile.DigestValueComputed;
} }
} }
...@@ -76,8 +76,9 @@ namespace HashingTool.ViewModel ...@@ -76,8 +76,9 @@ namespace HashingTool.ViewModel
{ {
get { get {
return _customerReport.Valid != null && _customerReport.Valid.Value && return _customerReport.Valid != null && _customerReport.Valid.Value &&
_customerReport.JobDigest == _jobFile.DigestValueComputed; _customerReport.JobDigestValue == _jobFile.DigestValueComputed;
} }
} }
} }
} }
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
VerticalAlignment="Top" /> VerticalAlignment="Top" />
<local:VectoXMLFileSelector DockPanel.Dock="Top" Margin="10,0" VerticalAlignment="Top" <local:VectoXMLFileSelector DockPanel.Dock="Top" Margin="10,0" VerticalAlignment="Top"
XMLFile="{Binding ComponentFile}" /> XMLFile="{Binding XMLFile}" />
<Grid DockPanel.Dock="Top" Margin="10,0,1,0"> <Grid DockPanel.Dock="Top" Margin="10,0,1,0">
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" /> <ColumnDefinition Width="Auto" />
...@@ -50,13 +51,13 @@ ...@@ -50,13 +51,13 @@
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,5"> <StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,5">
<Label> <Label>
<Label.Content> <Label.Content>
<TextBlock Text="{Binding XMLValidationErrors.Count, StringFormat='{}{0} Warnings/Errors'}" /> <TextBlock Text="{Binding XMLFile.XMLValidationErrors.Count, StringFormat='{}{0} Warnings/Errors'}" />
</Label.Content> </Label.Content>
<Label.Style> <Label.Style>
<Style TargetType="Label"> <Style TargetType="Label">
<Setter Property="Foreground" Value="Red" /> <Setter Property="Foreground" Value="Red" />
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding XMLValidationErrors.Count}" Value="0"> <DataTrigger Binding="{Binding XMLFile.XMLValidationErrors.Count}" Value="0">
<Setter Property="Foreground" Value="Black" /> <Setter Property="Foreground" Value="Black" />
</DataTrigger> </DataTrigger>
</Style.Triggers> </Style.Triggers>
...@@ -68,7 +69,7 @@ ...@@ -68,7 +69,7 @@
<Style TargetType="Button"> <Style TargetType="Button">
<Setter Property="IsEnabled" Value="True" /> <Setter Property="IsEnabled" Value="True" />
<Style.Triggers> <Style.Triggers>
<DataTrigger Binding="{Binding XMLValidationErrors.Count}" Value="0"> <DataTrigger Binding="{Binding XMLFile.XMLValidationErrors.Count}" Value="0">
<Setter Property="IsEnabled" Value="False" /> <Setter Property="IsEnabled" Value="False" />
</DataTrigger> </DataTrigger>
</Style.Triggers> </Style.Triggers>
...@@ -80,9 +81,14 @@ ...@@ -80,9 +81,14 @@
<Label Grid.Row="1" Grid.Column="0" Name="lblC14N" Content="Canonicalization:" HorizontalAlignment="Left" <Label Grid.Row="1" Grid.Column="0" Name="lblC14N" Content="Canonicalization:" HorizontalAlignment="Left"
Margin="0" /> Margin="0" />
<TextBox Grid.Row="1" Grid.Column="1" Name="lblC14NList" <TextBox Grid.Row="1" Grid.Column="1" Name="lblC14NList"
Text="{Binding CanonicalizaitionMethods, Converter={StaticResource CollectionConverter}}" Text="{Binding CanonicalizationMethods, Mode=OneWay, Converter={StaticResource CollectionConverter}}"
Margin="10,2" />
<Label Grid.Row="2" Grid.Column="0" Name="lblDigestMethod" Content="Digest Method:" HorizontalAlignment="Left"
Margin="0" />
<TextBox Grid.Row="2" Grid.Column="1" Name="tbDigestMethod"
Text="{Binding DigestMethod}"
Margin="10,2" /> Margin="10,2" />
<Button Grid.Row="1" Grid.Column="2" Content="Copy" Margin="10,2,0,2" HorizontalAlignment="Right" Width="75" <Button Grid.Row="3" Grid.Column="2" Content="Copy" Margin="10,2,0,2" HorizontalAlignment="Right" Width="75"
Click="Button_Click_1"> Click="Button_Click_1">
<Button.Style> <Button.Style>
<Style TargetType="Button"> <Style TargetType="Button">
...@@ -95,12 +101,12 @@ ...@@ -95,12 +101,12 @@
</Style> </Style>
</Button.Style> </Button.Style>
</Button> </Button>
<Label Grid.Row="2" Grid.Column="0" x:Name="lblDigestValue" Content="Digest Value:" HorizontalAlignment="Left" <Label Grid.Row="3" Grid.Column="0" x:Name="lblDigestValue" Content="Digest Value:" HorizontalAlignment="Left"
Margin="0" Style="{StaticResource DigestValueLabelStyle}" /> Margin="0" Style="{StaticResource DigestValueLabelStyle}" />
<TextBox Grid.Row="2" Grid.Column="1" x:Name="tbDigestValue" Text="{Binding DigestValue}" Margin="10,2" <TextBox Grid.Row="3" Grid.Column="1" x:Name="tbDigestValue" Text="{Binding DigestValue}" Margin="10,2"
VerticalAlignment="Top" RenderTransformOrigin="4.1,-2.1" Style="{StaticResource DigestValueTextboxStyle}" VerticalAlignment="Top" RenderTransformOrigin="4.1,-2.1" Style="{StaticResource DigestValueTextboxStyle}"
Foreground="{StaticResource Color.SuccessGreen}" /> Foreground="{StaticResource Color.SuccessGreen}" />
<ContentControl Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="0,0,0,0" <ContentControl Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="3" HorizontalAlignment="Center" Margin="0,0,0,0"
VerticalAlignment="Top" Width="66" Height="64"> VerticalAlignment="Top" Width="66" Height="64">
<ContentControl.LayoutTransform> <ContentControl.LayoutTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" /> <ScaleTransform ScaleX="1.5" ScaleY="1.5" />
......
...@@ -22,7 +22,7 @@ namespace HashingTool.Views ...@@ -22,7 +22,7 @@ namespace HashingTool.Views
private void Button_Click(object sender, RoutedEventArgs e) private void Button_Click(object sender, RoutedEventArgs e)
{ {
var dialog = new XMLValidationErrorsDialog(); var dialog = new XMLValidationErrorsDialog();
dialog.XMLErrors = (DataContext as HashComponentDataViewModel).XMLValidationErrors; dialog.XMLErrors = (DataContext as HashComponentDataViewModel).XMLFile.XMLValidationErrors;
dialog.ShowDialog(); dialog.ShowDialog();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment