Completed
Push — master ( e3e13b...942b41 )
by Charles
11:47
created

Utils::zero()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ncryptf;
4
5
use SodiumException;
6
7
final class Utils
8
{
9
    /**
10
     * Securely erases a memory block
11
     *
12
     * @param string $data
13
     * @return void
14
     */
15
    public static function zero(string $data)
16
    {
17
        return \sodium_memzero($data);
0 ignored issues
show
Bug introduced by
The call to sodium_memzero() has too few arguments starting with length. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        return /** @scrutinizer ignore-call */ \sodium_memzero($data);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
18
    }
19
20
    /**
21
     * Generates a crypto keypair
22
     *
23
     * @return array
24
     */
25
    public static function generateKeypair()
26
    {
27
        try {
28
            $keypair = \sodium_crypto_box_keypair();
29
            return [
30
                'public' => \sodium_crypto_box_secretkey($keypair),
31
                'secret' => \sodium_crypto_box_publickey($keypair)
32
            ];
33
        } catch (SodiumException $e) {
34
            throw new Exception($e->getMessage());
0 ignored issues
show
Bug introduced by
The type ncryptf\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
35
        }
36
    }
37
38
    /**
39
     * Generates a signing keypair
40
     *
41
     * @return array
42
     */
43
    public static function generateSigningKeypair()
44
    {
45
        try {
46
            $keypair = \sodium_crypto_sign_keypair();
47
            return [
48
                'public' => \sodium_crypto_sign_secretkey($keypair),
49
                'secret' => \sodium_crypto_sign_publickey($keypair)
50
            ];
51
        } catch (SodiumException $e) {
52
            throw new Exception($e->getMessage());
53
        }
54
    }
55
}
56