Skip to content

Commit c37fff9

Browse files
authored
Merge pull request #67 from Patater/deprecated-psa-errors
psa: Add backwards compatible error codes
2 parents 1ac5e6a + 5e6d24c commit c37fff9

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

include/psa/crypto_extra.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ extern "C" {
3737
/* UID for secure storage seed */
3838
#define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52
3939

40+
/*
41+
* Deprecated PSA Crypto error code definitions
42+
*/
43+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
44+
#define PSA_ERROR_UNKNOWN_ERROR \
45+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_GENERIC_ERROR )
46+
#endif
47+
48+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
49+
#define PSA_ERROR_OCCUPIED_SLOT \
50+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_ALREADY_EXISTS )
51+
#endif
52+
53+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
54+
#define PSA_ERROR_EMPTY_SLOT \
55+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_DOES_NOT_EXIST )
56+
#endif
57+
58+
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
59+
#define PSA_ERROR_INSUFFICIENT_CAPACITY \
60+
MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_INSUFFICIENT_DATA )
61+
#endif
62+
4063
/**
4164
* \brief Library deinitialization.
4265
*

scripts/generate_psa_constants.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,16 @@ def read_line(self, line):
167167
return
168168
elif (name.startswith('PSA_ERROR_') or name == 'PSA_SUCCESS') \
169169
and not parameter:
170+
if name in [
171+
'PSA_ERROR_UNKNOWN_ERROR',
172+
'PSA_ERROR_OCCUPIED_SLOT',
173+
'PSA_ERROR_EMPTY_SLOT',
174+
'PSA_ERROR_INSUFFICIENT_CAPACITY',
175+
]:
176+
# Ad hoc skipping of deprecated error codes, which share
177+
# numerical values with non-deprecated error codes
178+
return
179+
170180
self.statuses.add(name)
171181
elif name.startswith('PSA_KEY_TYPE_') and not parameter:
172182
self.key_types.add(name)

tests/scripts/test_psa_constant_names.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ def distribute_arguments(self, name):
131131
excluded_name_re = re.compile('_(?:GET|IS|OF)_|_(?:BASE|FLAG|MASK)\Z')
132132
# Additional excluded macros.
133133
# PSA_ALG_ECDH and PSA_ALG_FFDH are excluded for now as the script
134-
# currently doesn't support them.
134+
# currently doesn't support them. Deprecated errors are also excluded.
135135
excluded_names = set(['PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH',
136136
'PSA_ALG_FULL_LENGTH_MAC',
137137
'PSA_ALG_ECDH',
138-
'PSA_ALG_FFDH'])
138+
'PSA_ALG_FFDH',
139+
'PSA_ERROR_UNKNOWN_ERROR',
140+
'PSA_ERROR_OCCUPIED_SLOT',
141+
'PSA_ERROR_EMPTY_SLOT',
142+
'PSA_ERROR_INSUFFICIENT_CAPACITY',
143+
])
139144
argument_split_re = re.compile(r' *, *')
140145
def parse_header_line(self, line):
141146
'''Parse a C header line, looking for "#define PSA_xxx".'''

0 commit comments

Comments
 (0)