@@ -96,8 +96,9 @@ static String base64Encode(const byte in[], unsigned int length, const char* pre
9696 ******************************************************************************/
9797
9898ArduinoIoTCloudCertClass::ArduinoIoTCloudCertClass ()
99- : _certBuffer(NULL )
99+ : _certBuffer(nullptr )
100100, _certBufferLen(0 )
101+ , _publicKey(nullptr )
101102{
102103
103104}
@@ -106,7 +107,7 @@ ArduinoIoTCloudCertClass::~ArduinoIoTCloudCertClass()
106107{
107108 if (_certBuffer) {
108109 free (_certBuffer);
109- _certBuffer = NULL ;
110+ _certBuffer = nullptr ;
110111 }
111112}
112113
@@ -117,7 +118,6 @@ ArduinoIoTCloudCertClass::~ArduinoIoTCloudCertClass()
117118int ArduinoIoTCloudCertClass::begin ()
118119{
119120 memset (_compressedCert.data , 0x00 , CERT_COMPRESSED_CERT_LENGTH);
120- memset (_publicKey, 0x00 , CERT_PUBLIC_KEY_LENGTH);
121121 return 1 ;
122122}
123123
@@ -146,6 +146,9 @@ int ArduinoIoTCloudCertClass::buildCSR()
146146 out += appendIssuerOrSubject (_subjectData, out);
147147
148148 // public key
149+ if (_publicKey == nullptr ) {
150+ return 0 ;
151+ }
149152 out += appendPublicKey (_publicKey, out);
150153
151154 // terminator
@@ -243,6 +246,9 @@ int ArduinoIoTCloudCertClass::buildCert()
243246 out += appendIssuerOrSubject (_subjectData, out);
244247
245248 // public key
249+ if (_publicKey == nullptr ) {
250+ return 0 ;
251+ }
246252 out += appendPublicKey (_publicKey, out);
247253
248254 int authorityKeyIdLen = authorityKeyIdLength (_compressedCert.slot .two .values .authorityKeyId , CERT_AUTHORITY_KEY_ID_LENGTH);
@@ -377,7 +383,7 @@ int ArduinoIoTCloudCertClass::setAuthorityKeyId(const uint8_t authorityKeyId[],
377383
378384int ArduinoIoTCloudCertClass::setPublicKey (const byte* publicKey, int publicKeyLen) {
379385 if (publicKeyLen == CERT_PUBLIC_KEY_LENGTH) {
380- memcpy ( _publicKey, publicKey, CERT_PUBLIC_KEY_LENGTH) ;
386+ _publicKey = publicKey ;
381387 return 1 ;
382388 }
383389 return 0 ;
0 commit comments