Skip to content

Commit cc1122a

Browse files
JSONschema and python improvements
* JSON Schema manually updated to be more semantically valid. * Python script improved to be more verbose with exceptions * Templating file improved by adding an additional macro. Signed-off-by: Archana <[email protected]>
1 parent 5781c6b commit cc1122a

File tree

8 files changed

+161
-180
lines changed

8 files changed

+161
-180
lines changed

scripts/data_files/driver_jsons/driver_opaque_schema.json

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22
"$schema": "http://json-schema.org/draft-04/schema#",
33
"type": "object",
44
"properties": {
5-
"prefix": {
5+
"_comment": {
66
"type": "string"
77
},
8+
"prefix": {
9+
"type": "string",
10+
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
11+
},
812
"type": {
9-
"type": "string"
13+
"type": "string",
14+
"enum": ["opaque","transparent"]
1015
},
1116
"location": {
12-
"type": "string"
17+
"type": "string",
18+
"pattern": "^(0x|0X)?[a-fA-F0-9]+$"
1319
},
14-
"dependency": {
20+
"mbedtls/h_depend_on": {
1521
"type": "string"
1622
},
1723
"headers": {
1824
"type": "array",
19-
"items": [
20-
{
25+
"items": {
2126
"type": "string"
22-
}
23-
]
27+
},
28+
"minItems": 1,
29+
"uniqueItems": true
2430
},
2531
"capabilities": {
2632
"type": "array",
@@ -31,71 +37,33 @@
3137
"_comment": {
3238
"type": "string"
3339
},
34-
"depend_on": {
35-
"type": "string"
36-
},
37-
"entry_points": {
38-
"type": "array",
39-
"items": [
40-
{
41-
"type": "string"
42-
},
43-
{
44-
"type": "string"
45-
},
46-
{
47-
"type": "string"
48-
}
49-
]
50-
}
51-
},
52-
"required": [
53-
"_comment",
54-
"depend_on",
55-
"entry_points"
56-
]
57-
},
58-
{
59-
"type": "object",
60-
"properties": {
61-
"_comment": {
62-
"type": "string"
63-
},
64-
"depend_on": {
40+
"mbedtls/c_depend_on": {
6541
"type": "string"
6642
},
6743
"entry_points": {
6844
"type": "array",
69-
"items": [
70-
{
71-
"type": "string"
45+
"items": {
46+
"type": "string",
47+
"enum": ["import_key", "export_key", "export_public_key",
48+
"copy_key", "get_builtin_key"]
7249
},
73-
{
74-
"type": "string"
75-
}
76-
]
50+
"minItems": 1,
51+
"uniqueItems": true
7752
},
7853
"name": {
7954
"type": "object",
80-
"properties": {
81-
"copy_key": {
82-
"type": "string"
83-
},
84-
"get_builtin_key": {
85-
"type": "string"
55+
"patternProperties": {
56+
"^[A-Z_a-z][0-9A-Z_a-z]*$": {
57+
"type": "string",
58+
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
8659
}
8760
},
88-
"required": [
89-
"copy_key",
90-
"get_builtin_key"
91-
]
61+
"minItems": 1,
62+
"uniqueItems": true
9263
}
9364
},
9465
"required": [
95-
"_comment",
96-
"depend_on",
97-
"entry_points",
98-
"name"
66+
"entry_points"
9967
]
10068
}
10169
]
@@ -105,8 +73,6 @@
10573
"prefix",
10674
"type",
10775
"location",
108-
"dependency",
109-
"headers",
11076
"capabilities"
11177
]
11278
}

scripts/data_files/driver_jsons/driver_transparent_schema.json

Lines changed: 32 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
"$schema": "http://json-schema.org/draft-04/schema#",
33
"type": "object",
44
"properties": {
5-
"prefix": {
5+
"_comment": {
66
"type": "string"
77
},
8+
"prefix": {
9+
"type": "string",
10+
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
11+
},
812
"type": {
9-
"type": "string"
13+
"type": "string",
14+
"enum": ["opaque","transparent"]
1015
},
11-
"dependency": {
16+
"mbedtls/h_depend_on": {
1217
"type": "string"
1318
},
1419
"headers": {
1520
"type": "array",
16-
"items": [
17-
{
21+
"items": {
1822
"type": "string"
19-
}
20-
]
23+
},
24+
"minItems": 1,
25+
"uniqueItems": true
2126
},
2227
"capabilities": {
2328
"type": "array",
@@ -28,79 +33,46 @@
2833
"_comment": {
2934
"type": "string"
3035
},
31-
"depend_on": {
36+
"mbedtls/c_depend_on": {
3237
"type": "string"
3338
},
3439
"entry_points": {
3540
"type": "array",
36-
"items": [
37-
{
38-
"type": "string"
41+
"items": {
42+
"type": "string",
43+
"enum": ["import_key", "export_key", "export_public_key",
44+
"copy_key", "get_builtin_key"]
3945
},
40-
{
41-
"type": "string"
42-
}
43-
]
44-
},
45-
"fallback": {
46-
"type": "boolean"
47-
}
48-
},
49-
"required": [
50-
"_comment",
51-
"depend_on",
52-
"entry_points",
53-
"fallback"
54-
]
55-
},
56-
{
57-
"type": "object",
58-
"properties": {
59-
"_comment": {
60-
"type": "string"
61-
},
62-
"depend_on": {
63-
"type": "string"
64-
},
65-
"entry_points": {
66-
"type": "array",
67-
"items": [
68-
{
69-
"type": "string"
70-
}
71-
]
72-
},
73-
"fallback": {
74-
"type": "boolean"
46+
"minItems": 1,
47+
"uniqueItems": true
7548
},
7649
"name": {
7750
"type": "object",
78-
"properties": {
79-
"export_public_key": {
80-
"type": "string"
51+
"patternProperties": {
52+
"^[A-Z_a-z][0-9A-Z_a-z]*$": {
53+
"type": "string",
54+
"pattern": "^[A-Z_a-z][0-9A-Z_a-z]*$"
8155
}
8256
},
83-
"required": [
84-
"export_public_key"
85-
]
57+
"minItems": 1,
58+
"uniqueItems": true
59+
},
60+
"fallback": {
61+
"type": "boolean",
62+
"default": "false"
8663
}
8764
},
8865
"required": [
89-
"_comment",
90-
"depend_on",
91-
"entry_points",
92-
"fallback",
93-
"name"
66+
"entry_points"
9467
]
9568
}
96-
]
69+
],
70+
"default": []
9771
}
9872
},
9973
"required": [
10074
"prefix",
10175
"type",
102-
"dependency",
103-
"headers",
10476
"capabilities"
10577
]
10678
}

scripts/data_files/driver_jsons/mbedtls_test_opaque_driver.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
"prefix": "mbedtls_test",
33
"type": "opaque",
44
"location": "0x7fffff",
5-
"dependency": "defined(PSA_CRYPTO_DRIVER_TEST)",
5+
"mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
66
"headers": ["test/drivers/test_driver.h"],
77
"capabilities": [
88
{
9-
"_comment": "The mbedTLS opaque driver supports import key/export key/export_public key",
10-
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
9+
"_comment": "The Mbed TLS opaque driver supports import key/export key/export_public key",
10+
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
1111
"entry_points": ["import_key", "export_key", "export_public_key"]
1212
},
1313
{
14-
"_comment": "The mbedTLS opaque driver supports copy key/ get builtin key",
15-
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
16-
"entry_points": ["copy_key","get_builtin_key"],
14+
"_comment": "The Mbed TLS opaque driver supports copy key/ get builtin key",
15+
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
16+
"entry_points": ["copy_key", "get_builtin_key", "init"],
1717
"name": {"copy_key":"mbedtls_test_opaque_copy_key", "get_builtin_key":"mbedtls_test_opaque_get_builtin_key"}
1818
}
1919
]

scripts/data_files/driver_jsons/mbedtls_test_transparent_driver.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"prefix": "mbedtls_test",
33
"type": "transparent",
4-
"dependency": "defined(PSA_CRYPTO_DRIVER_TEST)",
4+
"mbedtls/h_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
55
"headers": ["test/drivers/test_driver.h"],
66
"capabilities": [
77
{
8-
"_comment": "The mbedTLS transparent driver supports import key/export key",
9-
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
8+
"_comment": "The Mbed TLS transparent driver supports import key/export key",
9+
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
1010
"entry_points": ["import_key", "export_key"],
1111
"fallback": true
1212
},
1313
{
14-
"_comment": "The mbedTLS transparent driver supports export_public key",
15-
"depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
14+
"_comment": "The Mbed TLS transparent driver supports export_public key",
15+
"mbedtls/c_depend_on": "defined(PSA_CRYPTO_DRIVER_TEST)",
1616
"entry_points": ["export_public_key"],
1717
"fallback": true,
1818
"name": {"export_public_key":"mbedtls_test_transparent_export_public_key"}

scripts/data_files/driver_templates/OS-template-opaque.jinja

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
{# One Shot function's dispatch code for opaque drivers.
2+
Expected inputs:
3+
* drivers: the list of driver descriptions.
4+
* entry_point: the name of the entry point that this function dispatches to.
5+
* entry_point_param(driver): the parameters to pass to the entry point.
6+
* nest_indent: number of extra spaces to indent the code to.
7+
-#}
18
{% for driver in drivers if driver.type == "opaque" -%}
29
{% for capability in driver.capabilities if entry_point in capability.entry_points -%}
3-
#if ({% if capability.depend_on is defined -%}{{ capability.depend_on }} {% else -%} {{ 1 }} {% endif %})
10+
#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %})
411
{%- filter indent(width = nest_indent) %}
512
case {{ driver.location }}:
6-
{% if capability.name is defined and entry_point in capability.name.keys() -%}
7-
return({{ capability.name[entry_point]}}({{entry_point_attributes(driver) | indent(20)}}));
8-
{% else -%}
9-
return({{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}}));
10-
{% endif -%}
13+
return( {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}}));
1114
{% endfilter -%}
1215
#endif
1316
{% endfor %}

scripts/data_files/driver_templates/OS-template-transparent.jinja

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
{# One Shot function's dispatch code for transparent drivers.
2+
Expected inputs:
3+
* drivers: the list of driver descriptions.
4+
* entry_point: the name of the entry point that this function dispatches to.
5+
* entry_point_param(driver): the parameters to pass to the entry point.
6+
* nest_indent: number of extra spaces to indent the code to.
7+
-#}
18
{% for driver in drivers if driver.type == "transparent" -%}
29
{% for capability in driver.capabilities if entry_point in capability.entry_points -%}
3-
#if ({% if capability.depend_on is defined -%}{{ capability.depend_on }} {% else -%} {{ 1 }} {% endif %})
10+
#if ({% if capability['mbedtls/c_depend_on'] is defined -%}{{ capability['mbedtls/c_depend_on'] }} {% else -%} {{ 1 }} {% endif %})
411
{%- filter indent(width = nest_indent) %}
5-
{% if capability.name is defined and entry_point in capability.name.keys() -%}
6-
status = {{ capability.name[entry_point]}}({{entry_point_attributes(driver) | indent(20)}});
7-
{% else -%}
8-
status = {{driver.prefix}}_{{driver.type}}_{{entry_point}}({{entry_point_attributes(driver) | indent(20)}});
9-
{% endif -%}
12+
status = {{ entry_point_name(capability, entry_point, driver) }}({{entry_point_param(driver) | indent(20)}});
1013

1114
if( status != PSA_ERROR_NOT_SUPPORTED )
1215
return( status );

0 commit comments

Comments
 (0)