-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWireFormat.cs
More file actions
37 lines (31 loc) · 995 Bytes
/
WireFormat.cs
File metadata and controls
37 lines (31 loc) · 995 Bytes
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
using System.Globalization;
namespace MonitorControl.Web;
internal static class WireFormat
{
internal static string ToHex(ReadOnlySpan<byte> data, int maxBytes = 512)
{
int n = Math.Min(data.Length, maxBytes);
if (n == 0)
{
return string.Empty;
}
return Convert.ToHexString(data[..n]);
}
internal static bool FirmwareGate(IConfiguration config, IHeaderDictionary headers)
{
string? env = Environment.GetEnvironmentVariable("MONITOR_CONTROL_ALLOW_DANGEROUS_FIRMWARE");
bool envOn = env is not null && (env.Equals("1", StringComparison.OrdinalIgnoreCase)
|| env.Equals("true", StringComparison.OrdinalIgnoreCase)
|| env.Equals("yes", StringComparison.OrdinalIgnoreCase));
bool cfg = config.GetValue("MonitorControl:AllowDangerousFirmware", false);
if (!envOn && !cfg)
{
return false;
}
if (!headers.TryGetValue("X-Firmware-Ack", out var ack))
{
return false;
}
return string.Equals(ack.ToString(), "CONFIRM", StringComparison.Ordinal);
}
}