OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
ChallengeResponse.cs
2using System;
4
6{
11 internal class ChallengeResponse : PayloadData
12 {
20 public ChallengeResponse(byte[] cUID, byte[] rndB, byte[] cryptogram, bool isUsingDefaultKey)
21 {
22 ClientUID = cUID;
23 RndB = rndB;
24 Cryptogram = cryptogram;
25 IsUsingDefaultKey = isUsingDefaultKey;
26 }
27
31 public byte[] ClientUID {get; }
32
36 public byte[] RndB { get; }
37
41 public byte[] Cryptogram { get; }
42
43 public bool IsUsingDefaultKey { get; }
44
49 public static ChallengeResponse ParseData(ReadOnlySpan<byte> data, bool isDefaultKey)
50 {
51 if (data.Length != 32)
52 {
53 throw new InvalidPayloadException($"Challenge response must be 32 bytes, received {data.Length}");
54 }
55
56 return new ChallengeResponse(
57 data.Slice(0, 8).ToArray(),
58 data.Slice(8, 8).ToArray(),
59 data.Slice(16, 16).ToArray(),
60 isDefaultKey
61 );
62 }
63
65 public override byte[] BuildData()
66 {
67 var payload = new byte[ClientUID.Length + RndB.Length + Cryptogram.Length];
68 ClientUID.CopyTo(payload, 0);
69 RndB.CopyTo(payload, ClientUID.Length);
70 Cryptogram.CopyTo(payload, ClientUID.Length + RndB.Length);
71
72 return payload;
73 }
74
76 public override byte Code => (byte)ReplyType.CrypticData;
77
79 public override bool IsSecurityInitialization => true;
80
82 public override ReadOnlySpan<byte> SecurityControlBlock()
83 {
84 return new byte[]
85 {
86 0x03,
87 (byte)SecurityBlockType.SecureConnectionSequenceStep2,
88 (byte)(IsUsingDefaultKey ? 0x00 : 0x01)
89 };
90 }
91 }
92}
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.
ReplyType
Identifies the type of OSDP protocol reply (PD -> ACU) message.
Definition ReplyType.cs:7