Passed
Pull Request — master (#14)
by Florent
06:01 queued 02:47
created

ExceptionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 80
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AESKW\Tests;
6
7
use AESKW\A128KW;
8
use AESKW\A192KW;
9
use InvalidArgumentException;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * These tests come from the RFC3394.
14
 *
15
 * @see https://www.ietf.org/rfc/rfc3394.txt#4
16
 *
17
 * @internal
18
 */
19
final class ExceptionTest extends TestCase
20
{
21
    /**
22
     * @test
23
     */
24
    public function integrityCheckFailed(): void
25
    {
26
        $this->expectExceptionMessage('Integrity check failed');
27
        $this->expectException(InvalidArgumentException::class);
28
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
29
        $data = hex2bin('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE4');
30
31
        A128KW::unwrap($kek, $data);
32
    }
33
34
    /**
35
     * @test
36
     */
37
    public function a128KWBadKeySize(): void
38
    {
39
        $this->expectExceptionMessage('Bad key size');
40
        $this->expectException(InvalidArgumentException::class);
41
        $kek = hex2bin('00010203040506070809101112131415');
42
        $data = hex2bin('0011223344');
43
44
        A128KW::wrap($kek, $data);
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function a128KWEmptyKey(): void
51
    {
52
        $this->expectExceptionMessage('Bad key size');
53
        $this->expectException(InvalidArgumentException::class);
54
        $kek = hex2bin('00010203040506070809101112131415');
55
        $data = hex2bin('');
56
57
        A128KW::wrap($kek, $data, true);
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function a128KWIntegrityNotVerified(): void
64
    {
65
        $this->expectExceptionMessage('Integrity check failed');
66
        $this->expectException(InvalidArgumentException::class);
67
        $kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8');
68
        $data = hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6b');
69
70
        A192KW::unwrap($kek, $data, true);
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function wrap64BitsKeyDataWith128BitKEK(): void
77
    {
78
        $this->expectExceptionMessage('Bad data');
79
        $this->expectException(InvalidArgumentException::class);
80
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
81
        $data = hex2bin('F4740052E82A2251');
82
83
        A128KW::unwrap($kek, $data);
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function badData(): void
90
    {
91
        $this->expectExceptionMessage('Integrity check failed');
92
        $this->expectException(InvalidArgumentException::class);
93
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
94
        $data = hex2bin('F4740052E82A225174CE86FBD7B805E6');
95
96
        A128KW::unwrap($kek, $data);
97
    }
98
}
99