Skip to content

Commit

Permalink
SE050: Add serialNumber(byte sn[])
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Oct 22, 2024
1 parent 103d4ab commit 687c009
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 20 additions & 5 deletions libraries/SE05X/src/SE05X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define SE05X_EC_SIGNATURE_HEADER_LENGTH 6
#define SE05X_EC_SIGNATURE_DER_LENGTH SE05X_EC_SIGNATURE_HEADER_LENGTH + SE05X_EC_SIGNATURE_RAW_LENGTH
#define SE05X_SHA256_LENGTH 32
#define SE05X_SN_LENGTH 18
#define SE05X_DER_BUFFER_SIZE 256
#define SE05X_TEMP_OBJECT 9999

Expand Down Expand Up @@ -158,17 +157,33 @@ int SE05XClass::readConfiguration(byte data[])
return 1;
}

int SE05XClass::serialNumber(byte sn[])
{
return serialNumber(sn, SE05X_SN_LENGTH);
}

int SE05XClass::serialNumber(byte sn[], size_t length)
{
size_t uidLen = length;

sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, sn, &uidLen);
if (length != uidLen) {
SE05X_PRINT_ERROR("Error in Se05x_API_ReadObject \n");
return 0;
}
return 1;
}

String SE05XClass::serialNumber()
{
String result = (char*)NULL;
byte UID[SE05X_SN_LENGTH];
size_t uidLen = 18;

sss_session_prop_get_au8(&_boot_ctx.session, kSSS_SessionProp_UID, UID, &uidLen);
serialNumber(UID, sizeof(UID));

result.reserve(uidLen*2);
result.reserve(SE05X_SN_LENGTH * 2);

for (int i = 0; i < uidLen; i++) {
for (size_t i = 0; i < SE05X_SN_LENGTH; i++) {
byte b = UID[i];

if (b < 16) {
Expand Down
4 changes: 4 additions & 0 deletions libraries/SE05X/src/SE05X.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#define SE05X_PRINT_ERROR
#endif

#define SE05X_SN_LENGTH 18

class SE05XClass
{
public:
Expand All @@ -41,6 +43,8 @@ class SE05XClass
int begin();
void end();

int serialNumber(byte sn[]);
int serialNumber(byte sn[], size_t length);
String serialNumber();

long random(long max);
Expand Down

0 comments on commit 687c009

Please sign in to comment.