Skip to content

Commit 8c11fc0

Browse files
committed
SecureElement: add utility class to read and write ArduinoCloud device-id
1 parent aa8adf1 commit 8c11fc0

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
This file is part of the Arduino_SecureElement library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
/******************************************************************************
12+
* INCLUDE
13+
******************************************************************************/
14+
15+
#include <utility/SElementArduinoCloudDeviceId.h>
16+
17+
int SElementArduinoCloudDeviceId::write(SecureElement & se, String & deviceId, const SElementArduinoCloudSlot idSlot)
18+
{
19+
byte device_id_bytes[ECP256_CERT_COMPRESSED_CERT_SLOT_LENGTH] = {0};
20+
21+
deviceId.getBytes(device_id_bytes, sizeof(device_id_bytes));
22+
23+
if (!se.writeSlot(static_cast<int>(idSlot), device_id_bytes, sizeof(device_id_bytes))) {
24+
return 0;
25+
}
26+
return 1;
27+
}
28+
29+
int SElementArduinoCloudDeviceId::read(SecureElement & se, String & deviceId, const SElementArduinoCloudSlot idSlot)
30+
{
31+
byte device_id_bytes[ECP256_CERT_COMPRESSED_CERT_SLOT_LENGTH] = {0};
32+
33+
if (!se.readSlot(static_cast<int>(idSlot), device_id_bytes, sizeof(device_id_bytes))) {
34+
return 0;
35+
}
36+
37+
deviceId = String(reinterpret_cast<char *>(device_id_bytes));
38+
return 1;
39+
}
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
This file is part of the Arduino_SecureElement library.
3+
4+
Copyright (c) 2024 Arduino SA
5+
6+
This Source Code Form is subject to the terms of the Mozilla Public
7+
License, v. 2.0. If a copy of the MPL was not distributed with this
8+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
11+
#ifndef SECURE_ELEMENT_ARDUINO_CLOUD_DEVICE_ID_H_
12+
#define SECURE_ELEMENT_ARDUINO_CLOUD_DEVICE_ID_H_
13+
14+
/******************************************************************************
15+
* INCLUDE
16+
******************************************************************************/
17+
18+
#include <utility/SElementArduinoCloud.h>
19+
20+
/******************************************************************************
21+
* CLASS DECLARATION
22+
******************************************************************************/
23+
24+
class SElementArduinoCloudDeviceId
25+
{
26+
public:
27+
28+
static int write(SecureElement & se, String & deviceId, const SElementArduinoCloudSlot idSlot);
29+
static int read(SecureElement & se, String & deviceId, const SElementArduinoCloudSlot idSlot);
30+
31+
};
32+
33+
#endif /* SECURE_ELEMENT_ARDUINO_CLOUD_DEVICE_ID_H_ */

0 commit comments

Comments
 (0)