-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtest_f_crypto_iv.py
65 lines (53 loc) · 2.28 KB
/
test_f_crypto_iv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Unit test suite for IV generation helper functions."""
import pytest
from aws_encryption_sdk.exceptions import ActionNotAllowedError
from aws_encryption_sdk.internal.crypto.iv import frame_iv, header_auth_iv, non_framed_body_iv
from aws_encryption_sdk.internal.defaults import ALGORITHM, MAX_FRAME_COUNT
pytestmark = [pytest.mark.functional, pytest.mark.local]
VALUES = {
'ivs': {
'header_auth': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
'non_framed': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01',
'frame': [
{
'sequence_number': 1,
'iv': b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
},
{
'sequence_number': 10000,
'iv': b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'\x10"
},
{
'sequence_number': 4294967295, # 2^32 - 1 :: max frame count
'iv': b'\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff'
}
]
}
}
@pytest.mark.parametrize('sequence_number, iv', [
(entry['sequence_number'], entry['iv'])
for entry in VALUES['ivs']['frame']
])
def test_framed_iv(sequence_number, iv):
assert frame_iv(ALGORITHM, sequence_number) == iv
@pytest.mark.parametrize('sequence_number', (-1, 0, MAX_FRAME_COUNT + 1))
def test_framed_iv_invalid_sequence_numbers(sequence_number):
with pytest.raises(ActionNotAllowedError) as excinfo:
frame_iv(ALGORITHM, sequence_number)
excinfo.match(r'Invalid frame sequence number: *')
def test_non_framed_body_iv():
assert non_framed_body_iv(ALGORITHM) == VALUES['ivs']['non_framed']
def test_header_auth_iv():
assert header_auth_iv(ALGORITHM) == VALUES['ivs']['header_auth']