@@ -96,8 +96,9 @@ static String base64Encode(const byte in[], unsigned int length, const char* pre
96
96
******************************************************************************/
97
97
98
98
ArduinoIoTCloudCertClass::ArduinoIoTCloudCertClass ()
99
- : _certBuffer(NULL )
99
+ : _certBuffer(nullptr )
100
100
, _certBufferLen(0 )
101
+ , _publicKey(nullptr )
101
102
{
102
103
103
104
}
@@ -106,7 +107,7 @@ ArduinoIoTCloudCertClass::~ArduinoIoTCloudCertClass()
106
107
{
107
108
if (_certBuffer) {
108
109
free (_certBuffer);
109
- _certBuffer = NULL ;
110
+ _certBuffer = nullptr ;
110
111
}
111
112
}
112
113
@@ -117,7 +118,6 @@ ArduinoIoTCloudCertClass::~ArduinoIoTCloudCertClass()
117
118
int ArduinoIoTCloudCertClass::begin ()
118
119
{
119
120
memset (_compressedCert.data , 0x00 , CERT_COMPRESSED_CERT_LENGTH);
120
- memset (_publicKey, 0x00 , CERT_PUBLIC_KEY_LENGTH);
121
121
return 1 ;
122
122
}
123
123
@@ -146,6 +146,9 @@ int ArduinoIoTCloudCertClass::buildCSR()
146
146
out += appendIssuerOrSubject (_subjectData, out);
147
147
148
148
// public key
149
+ if (_publicKey == nullptr ) {
150
+ return 0 ;
151
+ }
149
152
out += appendPublicKey (_publicKey, out);
150
153
151
154
// terminator
@@ -243,6 +246,9 @@ int ArduinoIoTCloudCertClass::buildCert()
243
246
out += appendIssuerOrSubject (_subjectData, out);
244
247
245
248
// public key
249
+ if (_publicKey == nullptr ) {
250
+ return 0 ;
251
+ }
246
252
out += appendPublicKey (_publicKey, out);
247
253
248
254
int authorityKeyIdLen = authorityKeyIdLength (_compressedCert.slot .two .values .authorityKeyId , CERT_AUTHORITY_KEY_ID_LENGTH);
@@ -377,7 +383,7 @@ int ArduinoIoTCloudCertClass::setAuthorityKeyId(const uint8_t authorityKeyId[],
377
383
378
384
int ArduinoIoTCloudCertClass::setPublicKey (const byte* publicKey, int publicKeyLen) {
379
385
if (publicKeyLen == CERT_PUBLIC_KEY_LENGTH) {
380
- memcpy ( _publicKey, publicKey, CERT_PUBLIC_KEY_LENGTH) ;
386
+ _publicKey = publicKey ;
381
387
return 1 ;
382
388
}
383
389
return 0 ;
0 commit comments