OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
SecurityInitialization.cs
1using System;
4
6
7internal class SecurityInitialization : CommandData
8{
10 public SecurityInitialization(byte[] serverRandomNumber, bool isDefaultKey)
11 {
12 ServerRandomNumber = serverRandomNumber ?? throw new ArgumentNullException(nameof(serverRandomNumber));
13 IsDefaultKey = isDefaultKey;
14 }
15
16 public byte[] ServerRandomNumber { get; }
17
18 public bool IsDefaultKey { get; }
19
21 public override CommandType CommandType => CommandType.SessionChallenge;
22
24 public override byte Code => (byte)CommandType;
25
27 public override bool IsSecurityInitialization => true;
28
30 public override ReadOnlySpan<byte> SecurityControlBlock()
31 {
32 return new byte[]
33 {
34 0x03,
35 (byte)SecurityBlockType.BeginNewSecureConnectionSequence,
36 (byte)(IsDefaultKey ? 0x00 : 0x01)
37 };
38 }
39
41 public override byte[] BuildData()
42 {
43 return ServerRandomNumber;
44 }
45
52 public static SecurityInitialization ParseData(ReadOnlySpan<byte> data, ReadOnlySpan<byte> securityControlBlock)
53 {
54 return new SecurityInitialization(data.ToArray(), securityControlBlock[2] == 0x01);
55 }
56}
Base class representing a payload of a PD command message.
ReadOnlySpan< byte > SecurityControlBlock()
Retrieves the security control block for a specific command data type.
byte[] BuildData()
Converts the payload into a byte array to be sent over the wire.
SecurityBlockType
Security Block Type values as defined by OSDP protocol.