Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create a pointer to a buffer in a typedef struct in C?

I getting an incompatible-pointer-types error when trying to Initialize a typedef struct with a pointer to a char buffer.
The struct looks like this:

typedef struct otCryptoKey
{
    const uint8_t *mKey;       ///< Pointer to the buffer containing key. NULL indicates to use `mKeyRef`.
    uint16_t       mKeyLength; ///< The key length in bytes (applicable when `mKey` is not NULL).
    uint32_t       mKeyRef;    ///< The PSA key ref (requires `mKey` to be NULL).
} otCryptoKey;

This is what i have tried, and i also tried to initialize with all the parameters in the struct.

    uint8_t mKey[16] = "1234567891012131";
    uint8_t *mKeyPointer = mKey;

    otCryptoKey *aKey = {mKeyPointer};

Can anyone figure out why i get this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You’re creating a pointer to a otCryptoKey and attempting to initialize it with a pointer to uint8_t. Those types are not compatible.

What you want is to create an otCryptoKey object and initialize the mKey member with that pointer.

otCryptoKey aKey = {mKey, sizeof mKey, 0};
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading