-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SAM_SESymmetricKeyEntryPropertiesDESFireDiv.cs
143 lines (133 loc) · 3.64 KB
/
SAM_SESymmetricKeyEntryPropertiesDESFireDiv.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
** File Name: SAM_SESymmetricKeyEntryPropertiesDESFireDiv.cs
** Author: s_eva
** Creation date: January 2024
** Description: This file regroups all properties of Diversification of a DESFire SAM-SE Key Entry.
** Licence: LGPLv3
** Copyright (c) 2023-Present Synchronic
*/
using CommunityToolkit.Mvvm.ComponentModel;
namespace Leosac.KeyManager.Library.KeyStore.SAM_SE
{
public class SAM_SESymmetricKeyEntryPropertiesDESFireDiv : ObservableValidator
{
public bool UidLinkEnable { get; set; } = false;
public uint UidLinkKeyNum { get; set; } = 0;
public string? UidLinkId { get; set; } = string.Empty;
public bool AidInverted { get; set; } = false;
private int siLenMax = 40;
public int SiLenMax
{
get => siLenMax;
set
{
SetProperty(ref siLenMax, value);
}
}
private bool enable = false;
public bool Enable
{
get => enable;
set
{
if (SetProperty(ref enable, value))
{
UpdateExpanded();
}
}
}
private bool expanded = false;
public bool Expanded
{
get => expanded;
set
{
SetProperty(ref expanded, value);
}
}
private bool keyInc = true;
public bool KeyInc
{
get => keyInc;
set
{
if (SetProperty(ref keyInc, value))
UpdateDESFireSiLenMax();
}
}
private byte[] si = [];
public byte[] Si
{
get => si;
set
{
SetProperty(ref si, value);
}
}
private string siString = string.Empty;
public string SiString
{
get => siString;
set
{
SetProperty(ref siString, value);
if (value.Length % 2 != 0)
{
WarningSi = true;
Si = [];
}
else
{
WarningSi = false;
// Convert the hex string to bytes
byte[] bytes = new byte[value.Length/2];
for (int i = 0; i < value.Length / 2; i++)
{
// Parse the two characters of the hex string into a byte
string hexByte = value.Substring(i * 2, 2);
// Conversion to actual byte
bytes[i] = Convert.ToByte(hexByte, 16);
}
Si = bytes;
}
}
}
private bool warningSi = false;
public bool WarningSi
{
get => warningSi;
set
{
SetProperty(ref warningSi, value);
}
}
private void UpdateExpanded()
{
if (Enable)
{
Expanded = true;
}
else
{
Expanded = false;
}
}
private void UpdateDESFireSiLenMax()
{
if (!KeyInc)
{
SiLenMax = 42;
}
else
{
SiLenMax = 40;
}
if (Si.Length*2 > SiLenMax)
{
byte[] temp = Enumerable.Repeat((byte)0x00, SiLenMax/2).ToArray();
Array.Copy(Si, temp, temp.Length);
Si = temp;
}
}
}
}