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