|
180 | 180 | }
|
181 | 181 | }
|
182 | 182 |
|
| 183 | + WHEN("Encode a message with provisioning public key") |
| 184 | + { |
| 185 | + ProvPublicKeyProvisioningMessage command; |
| 186 | + command.c.id = ProvisioningMessageId::ProvPublicKeyProvisioningMessageId; |
| 187 | + command.provPublicKey = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7JxCtXl5SvIrHmiasqyN4pyoXRlm44d5WXNpqmvJ\nk0tH8UpmIeHG7YPAkKLaqid95v/wLVoWeX5EbjxmlCkFtw==\n-----END PUBLIC KEY-----\n"; |
| 188 | + uint8_t buffer[512]; |
| 189 | + size_t bytes_encoded = sizeof(buffer); |
| 190 | + |
| 191 | + CBORMessageEncoder encoder; |
| 192 | + MessageEncoder::Status err = encoder.encode((Message*)&command, buffer, bytes_encoded); |
| 193 | + |
| 194 | + // Test the encoding is |
| 195 | + // DA 00012017 # tag(73751) |
| 196 | + // 81 # array(1) |
| 197 | + // 78 B4 # text(180) |
| 198 | + // 2D 2D 2D 2D 2D 4245 47 49 4E 20 50 55 42 4C 49 43204B45592D2D2D2D2D0A0A4D466B77457759484B6F5A497A6A3043415159494B6F5A497A6A3044415163445167414537 |
| 199 | + // 4A784374586C3553764972486D69617371794E3470796F58526C6D3434643557584E70716D764A0A6B3074483855706D49654847375950416B4B4C617169643935762F774C566F5765583545626A786D6C436B4674773D3D0A0A2D2D2D2D2D454E44205055424C4943204B45592D2D2D2D2D0A |
| 200 | + |
| 201 | + uint8_t expected_result[] = { |
| 202 | + 0xDA, 0x00, 0x01, 0x20, 0x17, 0x81, 0x78, 0xB2, |
| 203 | + 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x42, 0x45, 0x47, 0x49, 0x4E, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, |
| 204 | + 0x43, 0x20, 0x4B, 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A, 0x4D, 0x46, 0x6B, 0x77, |
| 205 | + 0x45, 0x77, 0x59, 0x48, 0x4B, 0x6F, 0x5A, 0x49, |
| 206 | + 0x7A, 0x6A, 0x30, 0x43, 0x41, 0x51, 0x59, 0x49, 0x4B, 0x6F, 0x5A, 0x49, |
| 207 | + 0x7A, 0x6A, 0x30, 0x44, 0x41, 0x51, 0x63, 0x44, 0x51, 0x67, 0x41, 0x45, |
| 208 | + 0x37, 0x4A, 0x78, 0x43, 0x74, 0x58, 0x6C, 0x35, 0x53, 0x76, 0x49, 0x72, |
| 209 | + 0x48, 0x6D, 0x69, 0x61, 0x73, 0x71, 0x79, 0x4E, 0x34, 0x70, 0x79, 0x6F, |
| 210 | + 0x58, 0x52, 0x6C, 0x6D, 0x34, 0x34, 0x64, 0x35, 0x57, 0x58, 0x4E, 0x70, |
| 211 | + 0x71, 0x6D, 0x76, 0x4A, 0x0A, 0x6B, 0x30, 0x74, 0x48, 0x38, 0x55, 0x70, |
| 212 | + 0x6D, 0x49, 0x65, 0x48, 0x47, 0x37, 0x59, 0x50, 0x41, 0x6B, 0x4B, 0x4C, |
| 213 | + 0x61, 0x71, 0x69, 0x64, 0x39, 0x35, 0x76, 0x2F, 0x77, 0x4C, 0x56, 0x6F, |
| 214 | + 0x57, 0x65, 0x58, 0x35, 0x45, 0x62, 0x6A, 0x78, 0x6D, 0x6C, 0x43, 0x6B, |
| 215 | + 0x46, 0x74, 0x77, 0x3D, 0x3D, 0x0A, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, |
| 216 | + 0x45, 0x4E, 0x44, 0x20, 0x50, 0x55, 0x42, 0x4C, 0x49, 0x43, 0x20, 0x4B, |
| 217 | + 0x45, 0x59, 0x2D, 0x2D, 0x2D, 0x2D, 0x2D, 0x0A |
| 218 | + }; |
| 219 | + |
| 220 | + THEN("The encoding is successful") { |
| 221 | + REQUIRE(err == MessageEncoder::Status::Complete); |
| 222 | + REQUIRE(bytes_encoded == sizeof(expected_result)); |
| 223 | + REQUIRE(memcmp(buffer, expected_result, sizeof(expected_result)) == 0); |
| 224 | + } |
| 225 | + } |
| 226 | + |
183 | 227 | WHEN("Encode a message with provisioning ble mac Address ")
|
184 | 228 | {
|
185 | 229 | BLEMacAddressProvisioningMessage command;
|
|
0 commit comments