Closed tweakch closed 3 years ago
As described in #35 the Stream could be analyzed prior to sending the transaction. Invalid Streams should be rejected.
The first byte appears to (not verified through specific reference) always be a major type 4 followed by the number of elements N.
An array (4 = 0b100) of length 3 = 0b0011 we be represented as 0b100_0011 resp. 0x83
0b100
0b0011
0b100_0011
0x83
Peek at the first byte and verify that it is a valid Type 4.
int type0 = 0x83 >> 4; // strip last four bits bool valid = type0 == 4; // verify it is an array (4)
The second byte apears to always be a map major tyoe 5 of the same length as bytes[0].
bytes[0]
An map (5 = 0b1001) of length 3 = 0b0011 we be represented as 0b1001_0011 resp. 0xA3
0b1001
0b1001_0011
0xA3
int type1 = 0xA3 >> 4; int len0 = 0x83 & 0xf0; int len1 = 0xA3 & 0xf0; bool valid = (type1 == 5) && (len0 == len1);
CBOR specification for reference
Description
As described in #35 the Stream could be analyzed prior to sending the transaction. Invalid Streams should be rejected.
Possible implementations
First byte
The first byte appears to (not verified through specific reference) always be a major type 4 followed by the number of elements N.
Example
An array (4 =
0b100
) of length 3 =0b0011
we be represented as0b100_0011
resp.0x83
Verification
Peek at the first byte and verify that it is a valid Type 4.
Second byte
The second byte apears to always be a map major tyoe 5 of the same length as
bytes[0]
.Example
An map (5 =
0b1001
) of length 3 =0b0011
we be represented as0b1001_0011
resp.0xA3
Verfication
CBOR specification for reference