Skip to content

Commit 2c400dc

Browse files
committed
imgtool: Add new tests for key operations
Refactor test_keys.py Move constants to separate file Verify key type in all testcases Add tests for generating keys with password Add more testcases for getpriv command Add more testcases for getpub command Add more testcases for getpubhash command Update list of expected to fail tests Signed-off-by: Rustam Ismayilov <[email protected]> Change-Id: If48a1c1496aced2e6f69f317f200aafc08d55538
1 parent 3f15dd0 commit 2c400dc

File tree

3 files changed

+618
-218
lines changed

3 files changed

+618
-218
lines changed

scripts/tests/conftest.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@
1616

1717
# List of tests expected to fail for some reason
1818
XFAILED_TESTS = {
19-
"tests/test_keys.py::test_getpriv[openssl-ed25519]",
20-
"tests/test_keys.py::test_getpriv[openssl-x25519]",
21-
"tests/test_keys.py::test_getpriv[pkcs8-rsa-2048]",
22-
"tests/test_keys.py::test_getpriv[pkcs8-rsa-3072]",
23-
"tests/test_keys.py::test_getpriv[pkcs8-ed25519]",
24-
"tests/test_keys.py::test_getpub[pem-ed25519]",
25-
"tests/test_keys.py::test_sign_verify[x25519]",
19+
# Unsupported key_type and format combinations
20+
"tests/test_keys.py::TestGetPriv::test_getpriv[openssl-ed25519]",
21+
"tests/test_keys.py::TestGetPriv::test_getpriv[openssl-x25519]",
22+
"tests/test_keys.py::TestGetPriv::test_getpriv[pkcs8-rsa-2048]",
23+
"tests/test_keys.py::TestGetPriv::test_getpriv[pkcs8-rsa-3072]",
24+
"tests/test_keys.py::TestGetPriv::test_getpriv[pkcs8-ed25519]",
25+
"tests/test_keys.py::TestGetPriv::test_getpriv_with_password[openssl-ed25519]",
26+
"tests/test_keys.py::TestGetPriv::test_getpriv_with_password[openssl-x25519]",
27+
"tests/test_keys.py::TestGetPriv::test_getpriv_with_password[pkcs8-rsa-2048]",
28+
"tests/test_keys.py::TestGetPriv::test_getpriv_with_password[pkcs8-rsa-3072]",
29+
"tests/test_keys.py::TestGetPriv::test_getpriv_with_password[pkcs8-ed25519]",
30+
# 'Ed25519' object has no attribute 'get_public_pem'
31+
"tests/test_keys.py::TestGetPub::test_getpub[pem-ed25519]",
32+
"tests/test_keys.py::TestGetPub::test_getpub_with_encoding[pem-ed25519]",
33+
"tests/test_keys.py::TestGetPub::test_getpub_no_outfile[pem-ed25519]",
34+
"tests/test_keys.py::TestLoading::test_load_key_public[pem-ed25519]",
35+
"tests/test_keys.py::TestLoading::test_load_key_public_with_password[pem-ed25519]",
2636
}
2737

2838

scripts/tests/constants.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2024 Arm Limited
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from imgtool import main as imgtool_main
18+
19+
# all supported key types for 'keygen'
20+
KEY_TYPES = [*imgtool_main.keygens]
21+
KEY_ENCODINGS = [*imgtool_main.valid_encodings]
22+
KEY_LANGS = [*imgtool_main.valid_langs]
23+
PUB_HASH_ENCODINGS = [*imgtool_main.valid_hash_encodings]
24+
PVT_KEY_FORMATS = [*imgtool_main.valid_formats]
25+
26+
OPENSSL_KEY_TYPES = {
27+
"rsa-2048": "Private-Key: (2048 bit, 2 primes)",
28+
"rsa-3072": "Private-Key: (3072 bit, 2 primes)",
29+
"ecdsa-p256": "Private-Key: (256 bit)",
30+
"ecdsa-p384": "Private-Key: (384 bit)",
31+
"ed25519": "ED25519 Private-Key:",
32+
"x25519": "X25519 Private-Key:",
33+
}
34+
GEN_KEY_EXT = ".key"
35+
PUB_KEY_EXT = ".pub"
36+
PUB_KEY_HASH_EXT = ".pubhash"
37+
38+
images_dir = "./images"
39+
signed_images_dir = images_dir + "/signed"
40+
41+
42+
def tmp_name(tmp_path, key_type, suffix=""):
43+
return tmp_path / (key_type + suffix)

0 commit comments

Comments
 (0)