Failed Conditions
Push — master ( 072e31...fa6436 )
by Florent
10s
created

ExceptionTest::testBadData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace AESKW\Tests;
13
14
use AESKW\A128KW;
15
use AESKW\A192KW;
16
use AESKW\A256KW;
17
use PHPUnit\Framework\TestCase;
18
19
/**
20
 * These tests come from the RFC3394.
21
 *
22
 * @see https://www.ietf.org/rfc/rfc3394.txt#4
23
 */
24
final class ExceptionTest extends TestCase
25
{
26
    /**
27
     * @expectedException        InvalidArgumentException
28
     * @expectedExceptionMessage Bad KEK size
29
     */
30
    public function testAESKWBadKEKSize()
31
    {
32
        $kek = hex2bin('00');
33
        $data = hex2bin('00112233445566778899AABBCCDDEEFF');
34
35
        A128KW::wrap($kek, $data);
36
    }
37
38
    /**
39
     * @expectedException        InvalidArgumentException
40
     * @expectedExceptionMessage Bad KEK size
41
     */
42
    public function testA128KWBadKEKSize()
43
    {
44
        $kek = hex2bin('0001020304050607');
45
        $data = hex2bin('00112233445566778899AABBCCDDEEFF');
46
47
        A128KW::wrap($kek, $data);
48
    }
49
50
    /**
51
     * @expectedException        InvalidArgumentException
52
     * @expectedExceptionMessage Bad KEK size
53
     */
54
    public function testA192KWBadKEKSize()
55
    {
56
        $kek = hex2bin('00010203040506070809101112131415');
57
        $data = hex2bin('00112233445566778899AABBCCDDEEFF');
58
59
        A192KW::wrap($kek, $data);
60
    }
61
62
    /**
63
     * @expectedException        InvalidArgumentException
64
     * @expectedExceptionMessage Bad KEK size
65
     */
66
    public function testA256KWBadKEKSize()
67
    {
68
        $kek = hex2bin('00010203040506070809101112131415');
69
        $data = hex2bin('00112233445566778899AABBCCDDEEFF');
70
71
        A256KW::wrap($kek, $data);
72
    }
73
74
    /**
75
     * @expectedException        InvalidArgumentException
76
     * @expectedExceptionMessage Integrity check failed
77
     */
78
    public function testIntegrityCheckFailed()
79
    {
80
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
81
        $data = hex2bin('1FA68B0A8112B447AEF34BD8FB5A7B829D3E862371D2CFE4');
82
83
        A128KW::unwrap($kek, $data);
84
    }
85
86
    /**
87
     * @expectedException        InvalidArgumentException
88
     * @expectedExceptionMessage Bad key size
89
     */
90
    public function testA128KWBadKeySize()
91
    {
92
        $kek = hex2bin('00010203040506070809101112131415');
93
        $data = hex2bin('0011223344');
94
95
        A128KW::wrap($kek, $data);
96
    }
97
98
    /**
99
     * @expectedException        InvalidArgumentException
100
     * @expectedExceptionMessage Bad key size
101
     */
102
    public function testA128KWEmptyKey()
103
    {
104
        $kek = hex2bin('00010203040506070809101112131415');
105
        $data = hex2bin('');
106
107
        A128KW::wrap($kek, $data, true);
108
    }
109
110
    /**
111
     * @expectedException        InvalidArgumentException
112
     * @expectedExceptionMessage Integrity check failed
113
     */
114
    public function testA128KWIntegrityNotVerified()
115
    {
116
        $kek = hex2bin('5840df6e29b02af1ab493b705bf16ea1ae8338f4dcc176a8');
117
        $data = hex2bin('138bdeaa9b8fa7fc61f97742e72248ee5ae6ae5360d1ae6a5f54f373fa543b6b');
118
119
        A192KW::unwrap($kek, $data, true);
120
    }
121
122
    /**
123
     * @expectedException        InvalidArgumentException
124
     * @expectedExceptionMessage Bad data
125
     */
126
    public function testWrap64BitsKeyDataWith128BitKEK()
127
    {
128
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
129
        $data = hex2bin('F4740052E82A2251');
130
131
        A128KW::unwrap($kek, $data);
132
    }
133
134
    /**
135
     * @expectedException        InvalidArgumentException
136
     * @expectedExceptionMessage Integrity check failed
137
     */
138
    public function testBadData()
139
    {
140
        $kek = hex2bin('000102030405060708090A0B0C0D0E0F');
141
        $data = hex2bin('F4740052E82A225174CE86FBD7B805E6');
142
143
        A128KW::unwrap($kek, $data);
144
    }
145
}
146