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

JWETest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 20
rs 10
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 PHPUnit\Framework\TestCase;
16
17
/**
18
 * This test comes from the JWE specification.
19
 *
20
 * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-39#appendix-A.3.3
21
 */
22
final class JWETest extends TestCase
23
{
24
    public function testCEKEncryption()
25
    {
26
        // The KEK
27
        $kek = base64_decode('GawgguFyGrWKav7AX4VKUg');
28
29
        // The CEK to encrypt (we convert it into a binary string)
30
        $data = [4, 211, 31, 197, 84, 157, 252, 254, 11, 100, 157, 250, 63, 170, 106, 206, 107, 124, 212, 45, 111, 107, 9, 219, 200, 177, 0, 240, 143, 156, 44, 207];
31
        foreach ($data as $key => $value) {
32
            $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
33
        }
34
        $data = hex2bin(implode('', $data));
35
36
        $wrapped = A128KW::wrap($kek, $data);
37
        $this->assertEquals(base64_decode('6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ'), $wrapped);
38
        $unwrapped = A128KW::unwrap($kek, $wrapped);
39
        $this->assertEquals($data, $unwrapped);
40
    }
41
}
42