I have a struct like this:
typedef struct
{
char private_key[ PRIVATE_KEY_SIZE ];
char certificate[ CERTIFICATE_SIZE ];
uint8_t cooee_key [ COOEE_KEY_SIZE ];
} platform_dct_security_t;
In my main function, I declared my variable:
platform_dct_security_t* dct_security = NULL;
Now I need to fill the arrays in this struct.
I also have my certificate defined like this:
#define CERTIFICATE_STRING \
"-----BEGIN CERTIFICATE-----\r\n"\
"MIIFIzCCBAugAwIBAgIETB0zITANBgkqhkiG9w0BAQUFADCBsTELMAkGA1UE\r\n"\
...
...
"uhZ2VrLWSJLyi6Y+t6xcaeoLP2ZFuQ==\r\n"\
"-----END CERTIFICATE-----\r\n"\
"\0"\
"\0"
So I proceeded:
memcpy( dct_security->certificate, CERTIFICATE_STRING, CERTIFICATE_SIZE );
printf( "\n%s\n", dct_security->certificate );
However, this prints out something garbage. I also tried this but it didn't work either:
(*dct_security) = { CERTIFICATE_STRING, PRIVATE_KEY_STRING, COOEE_KEY_STRING };
When I compile and run with this, it doesn't crash but it gets stuck and nothing is printed out.
If I define another char
array without having a struct
, it works like a charm:
char xyz[ CERTIFICATE_SIZE ];
memcpy( xyz, CERTIFICATE_STRING, CERTIFICATE_SIZE );
printf("\n%s\n", xyz);
Where am I going wrong? How do I fix this?