JWETest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A cEKEncryption() 0 17 2
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 PHPUnit\Framework\TestCase;
18
19
/**
20
 * This test comes from the JWE specification.
21
 *
22
 * @see https://tools.ietf.org/html/draft-ietf-jose-json-web-encryption-39#appendix-A.3.3
23
 *
24
 * @internal
25
 */
26
final class JWETest extends TestCase
27
{
28
    /**
29
     * @test
30
     */
31
    public function cEKEncryption(): void
32
    {
33
        // The KEK
34
        $kek = base64_decode('GawgguFyGrWKav7AX4VKUg', true);
35
36
        // The CEK to encrypt (we convert it into a binary string)
37
        $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];
38
        foreach ($data as $key => $value) {
39
            $data[$key] = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
40
        }
41
        $data = hex2bin(implode('', $data));
42
43
        $wrapped = A128KW::wrap($kek, $data);
44
        static::assertEquals(base64_decode('6KB707dM9YTIgHtLvtgWQ8mKwboJW3of9locizkDTHzBC2IlrT1oOQ', true), $wrapped);
45
        $unwrapped = A128KW::unwrap($kek, $wrapped);
46
        static::assertEquals($data, $unwrapped);
47
    }
48
}
49