-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pas
108 lines (87 loc) · 2.02 KB
/
main.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
unit Main;
{$mode objfpc}{$H+}
interface
uses
Classes,
SysUtils,
FileUtil,
Forms,
Controls,
Graphics,
Dialogs,
StdCtrls,
ComCtrls,
HlpHashFactory,
HlpIHash,
HlpIHashResult;
type
{ TMainForm }
TMainForm = class(TForm)
Memo1: TMemo;
StatusBarMain: TStatusBar;
procedure FormActivate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.lfm}
{ TMainForm }
procedure TMainForm.FormActivate(Sender: TObject);
var
Mode: string;
Fnamesrc: string;
FSHA2_512: IHash;
Result: IHashResult;
ResultStr: string;
Fnamesig: string;
Sigtext: string;
begin
MainForm.Caption := 'Filish v1.0.0';
Mode := ParamStr(1);
Fnamesrc := ParamStr(2);
Fnamesig := Concat(Fnamesrc, '.sha512.sig.txt');
FSHA2_512 := THashFactory.TCrypto.CreateSHA2_512();
Result := FSHA2_512.ComputeFile(Fnamesrc);
ResultStr := Result.ToString();
if Mode = 'generate' then
begin
MainForm.Memo1.Text := ResultStr;
with TStringList.Create do
try
Add(ResultStr);
SaveToFile(Fnamesig);
finally
Free;
end;
MainForm.StatusBarMain.Panels[0].Text :=
Concat('OK, sig written to: ', Fnamesig);
end
else if Mode = 'check' then
begin
with TStringList.Create do
try
LoadFromFile(Fnamesig);
// purge line endings from the text
Sigtext := StringReplace(GetText, LineEnding, '', [rfReplaceAll]);
Add(ResultStr);
MainForm.Memo1.Text:=GetText;
if CompareText(ResultStr, Sigtext) = 0 then
begin
MainForm.StatusBarMain.Panels[0].Text:='OK: Match';
//MainForm.Memo1.Text:='OK, hash of file matched contents of sig file';
end
else
begin
MainForm.StatusBarMain.Panels[0].Text:='NOT OK: Does not match';
//MainForm.Memo1.Text:='Warning! Hash of file does not match contents of sig file';
end;
finally
Free;
end;
end;
end;
end.