ExceptionTest   A
last analyzed

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A integrityCheckFailed() 0 9 1
A a128KWBadKeySize() 0 9 1
A a128KWEmptyKey() 0 9 1
A a128KWIntegrityNotVerified() 0 9 1
A wrap64BitsKeyDataWith128BitKEK() 0 9 1
A badData() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2020 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace AESKW\Tests;
15
16
use AESKW\A128KW;
17
use AESKW\A192KW;
18
use InvalidArgumentException;
19
use PHPUnit\Framework\TestCase;
20
21
/**
22
 * These tests come from the RFC3394.
23
 *
24
 * @see https://www.ietf.org/rfc/rfc3394.txt#4
25
 *
26
 * @internal
27
 */
28
final class ExceptionTest extends TestCase
29
{
30
    /**
31
     * @test
32
     */
33
    public function integrityCheckFailed(): void
34
    {
35
        $this->expectExceptionMessage('Integrity check failed');
36
        $this->expectException(InvalidArgumentException::class);
37
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
38
        $data = hex2bin('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE4');
39
40
        A128KW::unwrap($kek, $data);
41
    }
42
43
    /**
44
     * @test
45
     */
46
    public function a128KWBadKeySize(): void
47
    {
48
        $this->expectExceptionMessage('Bad key size');
49
        $this->expectException(InvalidArgumentException::class);
50
        $kek = hex2bin('00010203040506070809101112131415');
51
        $data = hex2bin('0011223344');
52
53
        A128KW::wrap($kek, $data);
54
    }
55
56
    /**
57
     * @test
58
     */
59
    public function a128KWEmptyKey(): void
60
    {
61
        $this->expectExceptionMessage('Bad key size');
62
        $this->expectException(InvalidArgumentException::class);
63
        $kek = hex2bin('00010203040506070809101112131415');
64
        $data = hex2bin('');
65
66
        A128KW::wrap($kek, $data, true);
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function a128KWIntegrityNotVerified(): void
73
    {
74
        $this->expectExceptionMessage('Integrity check failed');
75
        $this->expectException(InvalidArgumentException::class);
76
        $kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8');
77
        $data = hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6b');
78
79
        A192KW::unwrap($kek, $data, true);
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function wrap64BitsKeyDataWith128BitKEK(): void
86
    {
87
        $this->expectExceptionMessage('Bad data');
88
        $this->expectException(InvalidArgumentException::class);
89
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
90
        $data = hex2bin('F4740052E82A2251');
91
92
        A128KW::unwrap($kek, $data);
93
    }
94
95
    /**
96
     * @test
97
     */
98
    public function badData(): void
99
    {
100
        $this->expectExceptionMessage('Integrity check failed');
101
        $this->expectException(InvalidArgumentException::class);
102
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
103
        $data = hex2bin('F4740052E82A225174CE86FBD7B805E6');
104
105
        A128KW::unwrap($kek, $data);
106
    }
107
}
108