pub unsafe extern "C" fn psa_import_key(
    attributes: *const psa_key_attributes_t,
    data: *const u8,
    data_length: usize,
    key: *mut mbedtls_svc_key_id_t
) -> psa_status_t
Expand description

\brief Import a key in binary format.

This function supports any output from psa_export_key(). Refer to the documentation of psa_export_public_key() for the format of public keys and to the documentation of psa_export_key() for the format for other key types.

The key data determines the key size. The attributes may optionally specify a key size; in this case it must match the size determined from the key data. A key size of 0 in \p attributes indicates that the key size is solely determined by the key data.

Implementations must reject an attempt to import a key of size 0.

This specification supports a single format for each key type. Implementations may support other formats as long as the standard format is supported. Implementations that support other formats should ensure that the formats are clearly unambiguous so as to minimize the risk that an invalid input is accidentally interpreted according to a different format.

\param[in] attributes The attributes for the new key. The key size is always determined from the \p data buffer. If the key size in \p attributes is nonzero, it must be equal to the size from \p data. \param[out] key On success, an identifier to the newly created key. For persistent keys, this is the key identifier defined in \p attributes. \c 0 on failure. \param[in] data Buffer containing the key data. The content of this buffer is interpreted according to the type declared in \p attributes. All implementations must support at least the format described in the documentation of psa_export_key() or psa_export_public_key() for the chosen type. Implementations may allow other formats, but should be conservative: implementations should err on the side of rejecting content if it may be erroneous (e.g. wrong type or truncated data). \param data_length Size of the \p data buffer in bytes.

\retval #PSA_SUCCESS Success. If the key is persistent, the key material and the key’s metadata have been saved to persistent storage. \retval #PSA_ERROR_ALREADY_EXISTS This is an attempt to create a persistent key, and there is already a persistent key with the given identifier. \retval #PSA_ERROR_NOT_SUPPORTED The key type or key size is not supported, either by the implementation in general or in this particular persistent location. \retval #PSA_ERROR_INVALID_ARGUMENT The key attributes, as a whole, are invalid, or the key data is not correctly formatted, or the size in \p attributes is nonzero and does not match the size of the key data. \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription \retval #PSA_ERROR_INSUFFICIENT_STORAGE \emptydescription \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription \retval #PSA_ERROR_DATA_CORRUPT \emptydescription \retval #PSA_ERROR_DATA_INVALID \emptydescription \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription \retval #PSA_ERROR_BAD_STATE The library has not been previously initialized by psa_crypto_init(). It is implementation-dependent whether a failure to initialize results in this error code.