Convert code samples to the new attribute-based key creation API

This commit is contained in:
Gilles Peskine 2019-05-21 15:56:03 +02:00
parent a0c0655c91
commit d7d43b9791

View file

@ -641,14 +641,16 @@
* The following code illustrates how to allocate enough memory to export * The following code illustrates how to allocate enough memory to export
* a key by querying the key type and size at runtime. * a key by querying the key type and size at runtime.
* \code{c} * \code{c}
* psa_key_type_t key_type; * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
* size_t key_bits;
* psa_status_t status; * psa_status_t status;
* status = psa_get_key_information(key, &key_type, &key_bits); * status = psa_get_key_attributes(key, &attributes);
* if (status != PSA_SUCCESS) handle_error(...); * if (status != PSA_SUCCESS) handle_error(...);
* psa_key_type_t key_type = psa_get_key_type(&attributes);
* size_t key_bits = psa_get_key_bits(&attributes);
* size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits); * size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits);
* psa_reset_key_attributes(&attributes);
* unsigned char *buffer = malloc(buffer_size); * unsigned char *buffer = malloc(buffer_size);
* if (buffer != NULL) handle_error(...); * if (buffer == NULL) handle_error(...);
* size_t buffer_length; * size_t buffer_length;
* status = psa_export_key(key, buffer, buffer_size, &buffer_length); * status = psa_export_key(key, buffer, buffer_size, &buffer_length);
* if (status != PSA_SUCCESS) handle_error(...); * if (status != PSA_SUCCESS) handle_error(...);
@ -658,15 +660,17 @@
* public key type. You can use the macro #PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR * public key type. You can use the macro #PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR
* to convert a key pair type to the corresponding public key type. * to convert a key pair type to the corresponding public key type.
* \code{c} * \code{c}
* psa_key_type_t key_type; * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
* size_t key_bits;
* psa_status_t status; * psa_status_t status;
* status = psa_get_key_information(key, &key_type, &key_bits); * status = psa_get_key_attributes(key, &attributes);
* if (status != PSA_SUCCESS) handle_error(...); * if (status != PSA_SUCCESS) handle_error(...);
* psa_key_type_t key_type = psa_get_key_type(&attributes);
* psa_key_type_t public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type); * psa_key_type_t public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type);
* size_t key_bits = psa_get_key_bits(&attributes);
* size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(public_key_type, key_bits); * size_t buffer_size = PSA_KEY_EXPORT_MAX_SIZE(public_key_type, key_bits);
* psa_reset_key_attributes(&attributes);
* unsigned char *buffer = malloc(buffer_size); * unsigned char *buffer = malloc(buffer_size);
* if (buffer != NULL) handle_error(...); * if (buffer == NULL) handle_error(...);
* size_t buffer_length; * size_t buffer_length;
* status = psa_export_public_key(key, buffer, buffer_size, &buffer_length); * status = psa_export_public_key(key, buffer, buffer_size, &buffer_length);
* if (status != PSA_SUCCESS) handle_error(...); * if (status != PSA_SUCCESS) handle_error(...);