OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
EncryptionKeyConfiguration.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
6
8{
13 {
19 public EncryptionKeyConfiguration(KeyType keyType, byte[] keyData)
20 {
21 KeyType = keyType;
22 KeyData = keyData;
23 }
24
28 public KeyType KeyType { get; }
29
33 public byte[] KeyData { get; }
34
36 public override CommandType CommandType => CommandType.KeySet;
37
39 public override byte Code => (byte)CommandType;
40
42 public override ReadOnlySpan<byte> SecurityControlBlock() => SecurityBlock.CommandMessageWithDataSecurity;
43
45 public override byte[] BuildData()
46 {
47 var data = new List<byte>
48 {
49 (byte)KeyType,
50 (byte)KeyData.Length
51 };
52 data.AddRange(KeyData);
53
54 return data.ToArray();
55 }
56
60 public static EncryptionKeyConfiguration ParseData(ReadOnlySpan<byte> data)
61 {
62 byte keyLength = data[1];
63
64 return new EncryptionKeyConfiguration((KeyType)data[0], data.Slice(2, keyLength).ToArray());
65 }
66
68 public override string ToString()
69 {
70 var sb = new StringBuilder();
71 sb.AppendLine($" Key Type: {KeyType}");
72 sb.AppendLine($"Key Length: {KeyData.Length} bytes");
73 sb.AppendLine($" Key Data: {BitConverter.ToString(KeyData)}");
74 return sb.ToString();
75 }
76 }
77}
Contains standard Security Control Block data that can be used when building messages.
Base class representing a payload of a PD command message.
override ReadOnlySpan< byte > SecurityControlBlock()
EncryptionKeyConfiguration(KeyType keyType, byte[] keyData)
Initializes a new instance of the EncryptionKeyConfiguration class.
static EncryptionKeyConfiguration ParseData(ReadOnlySpan< byte > data)
Parses the message payload bytes.