McryptCryptoTest::testIntegrity()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 24

Duplication

Lines 5
Ratio 20.83 %

Importance

Changes 0
Metric Value
dl 5
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 6
nop 0
1
<?php
2
3
namespace SilverStripe\HybridSessions\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\HybridSessions\Crypto\McryptCrypto;
7
8
/**
9
 * @requires extension mcrypt
10
 * @skip
11
 */
12
class McryptCryptoTest extends SapphireTest
13
{
14
    public function testIntegrity()
15
    {
16
        $this->markTestSkipped(
17
            'McryptCrypto is losing zero bytes at the end of messages: ' .
18
            'https://github.com/silverstripe/silverstripe-hybridsessions/issues/53'
19
        );
20
21
        $error_reporting = ini_set('error_reporting', (int) ini_get('error_reporting') & ~E_DEPRECATED);
22
23
        try {
24
            $key = random_bytes(8);
25
            $salt = random_bytes(16);
26
27
            $handler = new McryptCrypto($key, $salt);
0 ignored issues
show
Deprecated Code introduced by
The class SilverStripe\HybridSessions\Crypto\McryptCrypto has been deprecated with message: 2.2.0 The PHP mcrypt library is deprecated. Please use OpenSSLCrypto instead. WARNING: Please beware that McryptCrypto does not preserve zero bytes at the end of encrypted messages. Thus, a message such as "data\x00" will become "data" after encrypt-decrypt. As such, it is not binary safe. It is guaranteed for UTF-8 encoded text not to have zero bytes. However, other encodings may contain those. For example, be careful with UTF-16LE, since characters less than U+0100 are very common.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
28
29 View Code Duplication
            for ($i = 0; $i < 1000; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
                $data = random_bytes(1024 * 4);
31
32
                $this->assertEquals($data, $handler->decrypt($handler->encrypt($data)));
33
            }
34
        } finally {
35
            ini_set('error_reporting', $error_reporting);
36
        }
37
    }
38
}
39