Failed Conditions
Push — master ( 339400...89d9e2 )
by Florent
01:13
created

ExceptionTest::a128KWBadKeySize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2018 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 PHPUnit\Framework\TestCase;
19
20
/**
21
 * These tests come from the RFC3394.
22
 *
23
 * @see https://www.ietf.org/rfc/rfc3394.txt#4
24
 */
25
final class ExceptionTest extends TestCase
26
{
27
    /**
28
     * @expectedException        \InvalidArgumentException
29
     * @expectedExceptionMessage Integrity check failed
30
     *
31
     * @test
32
     */
33
    public function integrityCheckFailed()
34
    {
35
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
36
        $data = hex2bin('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE4');
37
38
        A128KW::unwrap($kek, $data);
39
    }
40
41
    /**
42
     * @expectedException        \InvalidArgumentException
43
     * @expectedExceptionMessage Bad key size
44
     *
45
     * @test
46
     */
47
    public function a128KWBadKeySize()
48
    {
49
        $kek = hex2bin('00010203040506070809101112131415');
50
        $data = hex2bin('0011223344');
51
52
        A128KW::wrap($kek, $data);
53
    }
54
55
    /**
56
     * @expectedException        \InvalidArgumentException
57
     * @expectedExceptionMessage Bad key size
58
     *
59
     * @test
60
     */
61
    public function a128KWEmptyKey()
62
    {
63
        $kek = hex2bin('00010203040506070809101112131415');
64
        $data = hex2bin('');
65
66
        A128KW::wrap($kek, $data, true);
67
    }
68
69
    /**
70
     * @expectedException        \InvalidArgumentException
71
     * @expectedExceptionMessage Integrity check failed
72
     *
73
     * @test
74
     */
75
    public function a128KWIntegrityNotVerified()
76
    {
77
        $kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8');
78
        $data = hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6b');
79
80
        A192KW::unwrap($kek, $data, true);
81
    }
82
83
    /**
84
     * @expectedException        \InvalidArgumentException
85
     * @expectedExceptionMessage Bad data
86
     *
87
     * @test
88
     */
89
    public function wrap64BitsKeyDataWith128BitKEK()
90
    {
91
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
92
        $data = hex2bin('F4740052E82A2251');
93
94
        A128KW::unwrap($kek, $data);
95
    }
96
97
    /**
98
     * @expectedException        \InvalidArgumentException
99
     * @expectedExceptionMessage Integrity check failed
100
     *
101
     * @test
102
     */
103
    public function badData()
104
    {
105
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
106
        $data = hex2bin('F4740052E82A225174CE86FBD7B805E6');
107
108
        A128KW::unwrap($kek, $data);
109
    }
110
}
111