Debian Codegraph @

tests/test_defs.py

raw
1 # Copyright 2016-2018 Yubico AB
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from yubihsm.defs import ALGORITHM, CAPABILITY
16 from cryptography.hazmat.primitives.asymmetric import ec
17
18 import pytest
19
20
21 @pytest.mark.parametrize(
22 "algorithm, curve",
23 [
24 (ALGORITHM.EC_P224, ec.SECP224R1),
25 (ALGORITHM.EC_P256, ec.SECP256R1),
26 (ALGORITHM.EC_P384, ec.SECP384R1),
27 (ALGORITHM.EC_P521, ec.SECP521R1),
28 (ALGORITHM.EC_K256, ec.SECP256K1),
29 (ALGORITHM.EC_BP256, ec.BrainpoolP256R1),
30 (ALGORITHM.EC_BP384, ec.BrainpoolP384R1),
31 (ALGORITHM.EC_BP512, ec.BrainpoolP512R1),
32 ],
33 )
34 def test_algorithm_to_from_curve(algorithm, curve):
35 assert isinstance(algorithm.to_curve(), curve)
36 assert algorithm == ALGORITHM.for_curve(curve())
37
38
39 def test_capability_all_includes_everything():
40 assert CAPABILITY.ALL == sum(CAPABILITY)
41 assert CAPABILITY.NONE == 0
42
43 for c in CAPABILITY:
44 assert c in CAPABILITY.ALL
45 assert c not in CAPABILITY.NONE