From 687c00950b163c1db03df064040c200a3b52802f Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 22 Oct 2024 11:55:59 +0200 Subject: [PATCH] SE050: Add serialNumber(byte sn[]) --- libraries/SE05X/src/SE05X.cpp | 25 ++++++++++++++++++++----- libraries/SE05X/src/SE05X.h | 4 ++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libraries/SE05X/src/SE05X.cpp b/libraries/SE05X/src/SE05X.cpp index c9a322bc4..72d09c08e 100644 --- a/libraries/SE05X/src/SE05X.cpp +++ b/libraries/SE05X/src/SE05X.cpp @@ -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 @@ -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) { diff --git a/libraries/SE05X/src/SE05X.h b/libraries/SE05X/src/SE05X.h index a01eb8b01..db1427341 100644 --- a/libraries/SE05X/src/SE05X.h +++ b/libraries/SE05X/src/SE05X.h @@ -32,6 +32,8 @@ #define SE05X_PRINT_ERROR #endif +#define SE05X_SN_LENGTH 18 + class SE05XClass { public: @@ -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);