From d75adfcb3b7093c7faaabf5896747f9981fd879c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 17 Feb 2021 18:04:28 +0100 Subject: [PATCH] KeyType: do a sanity check on the key type expression Signed-off-by: Gilles Peskine --- scripts/mbedtls_dev/crypto_knowledge.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/mbedtls_dev/crypto_knowledge.py b/scripts/mbedtls_dev/crypto_knowledge.py index fb96ec07e..4ff4f16ef 100644 --- a/scripts/mbedtls_dev/crypto_knowledge.py +++ b/scripts/mbedtls_dev/crypto_knowledge.py @@ -36,6 +36,7 @@ class KeyType: passing an expression of the form 'PSA_KEY_TYPE_xxx(param1, param2)' in `name` as a string. """ + self.name = name.strip() """The key type macro name (``PSA_KEY_TYPE_xxx``). @@ -54,10 +55,13 @@ class KeyType: None if the key type is a macro without arguments. """ + assert re.match(r'PSA_KEY_TYPE_\w+\Z', self.name) + self.expression = self.name """A C expression whose value is the key type encoding.""" if self.params is not None: self.expression += '(' + ', '.join(self.params) + ')' + self.private_type = re.sub(r'_PUBLIC_KEY\Z', r'_KEY_PAIR', self.name) """The key type macro name for the corresponding key pair type.