Skip to content

Commit

Permalink
Add serialNumber(byte sn[], size_t length)
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Dec 5, 2024
1 parent 5030931 commit a585642
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/SecureElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,20 @@ int SecureElement::SHA256(const uint8_t *buffer, size_t size, uint8_t *digest)
#endif
}

int SecureElement::serialNumber(byte sn[], size_t length)
{
#if defined(SECURE_ELEMENT_IS_SE050)
return _secureElement.serialNumber(sn, length);
#else
if (sn == nullptr || length < SE_SN_LENGTH) {
return 0;
}
uint8_t tmp[12];
if (!_secureElement.serialNumber(tmp)) {
return 0;
}
memcpy(sn, tmp, SE_SN_LENGTH);
return 1;
#endif
}

9 changes: 9 additions & 0 deletions src/SecureElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
#define SE_SHA256_BUFFER_LENGTH 32
#define SE_CERT_BUFFER_LENGTH 1024

#if defined(SECURE_ELEMENT_IS_SE050)
#define SE_SN_LENGTH SE05X_SN_LENGTH
#elif defined(SECURE_ELEMENT_IS_ECCX08)
#define SE_SN_LENGTH 9
#elif defined(SECURE_ELEMENT_IS_SOFTSE)
#define SE_SN_LENGTH 6
#endif

/******************************************************************************
* CLASS DECLARATION
******************************************************************************/
Expand All @@ -52,6 +60,7 @@ class SecureElement

inline int serialNumber(byte sn[]) { return _secureElement.serialNumber(sn); }
inline String serialNumber() { return _secureElement.serialNumber(); }
int serialNumber(byte sn[], size_t length);

inline long random(long min, long max) { return this->_secureElement.random(min, max); };
inline long random(long max) { return this->_secureElement.random(max); };
Expand Down

0 comments on commit a585642

Please sign in to comment.