Skip to content

Add serialNumber(byte sn[], size_t length) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading