-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCryptoService.php
More file actions
96 lines (84 loc) · 2.66 KB
/
CryptoService.php
File metadata and controls
96 lines (84 loc) · 2.66 KB
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
<?php
declare(strict_types=1);
namespace CryptoService;
final class CryptoService
{
public static function computePan(string $content): string
{
return ComputePan::compute($content);
}
public static function computeDan(
string $content,
string $templateId,
string $modelUsed = '',
): string {
return ComputeDan::compute($content, $templateId, $modelUsed);
}
public static function computePan2(string $panBase, string $panCompared): string
{
return ComputePan2::compute($panBase, $panCompared);
}
public static function computeCan(
string $parentPan,
string $childContent,
int $childIndex = 0,
): string {
return ComputeCan::compute($parentPan, $childContent, $childIndex);
}
public static function epochStamp(): int
{
return Crypto::epochStamp();
}
public static function epochStampToIso(int $epochStamp): string
{
return Crypto::epochStampToIso($epochStamp);
}
public static function computeAll(
string $content,
string $templateId = '',
string $modelUsed = '',
?string $parentPan = null,
int $childIndex = 0,
bool $isAi = false,
): array {
return [
'pan' => ComputePan::compute($content),
'dan' => $isAi
? ComputeDan::compute($content, $templateId, $modelUsed)
: null,
'can' => $parentPan !== null
? ComputeCan::compute($parentPan, $content, $childIndex)
: null,
'epoch_stamp' => Crypto::epochStamp(),
];
}
public static function verifySop(
string $content,
string $storedPan,
?string $storedDan = null,
?string $storedCan = null,
string $templateId = '',
string $modelUsed = '',
?string $parentPan = null,
int $childIndex = 0,
): array {
$failed = [];
if (ComputePan::compute($content) !== $storedPan) {
$failed[] = 'pan';
}
if ($storedDan !== null) {
if (ComputeDan::compute($content, $templateId, $modelUsed) !== $storedDan) {
$failed[] = 'dan';
}
}
if ($storedCan !== null && $parentPan !== null) {
if (ComputeCan::compute($parentPan, $content, $childIndex) !== $storedCan) {
$failed[] = 'can';
}
}
return [
'valid' => empty($failed),
'failed' => $failed,
];
}
}