• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aplus-framework / crypto / 12003099846

23 Aug 2024 08:22PM UTC coverage: 100.0%. Remained the same
12003099846

push

github

natanfelles
Upgrade coding standard

132 of 132 relevant lines covered (100.0%)

1.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/BoxTrait.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Crypto Library.
4
 *
5
 * (c) Natan Felles <natanfelles@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Framework\Crypto;
11

12
use Exception;
13
use SensitiveParameter;
14
use SodiumException;
15

16
/**
17
 * Trait BoxTrait.
18
 *
19
 * @package crypto
20
 */
21
trait BoxTrait
22
{
23
    /**
24
     * Makes a keypair.
25
     *
26
     * @throws SodiumException
27
     */
28
    public static function makeKeyPair() : string
29
    {
30
        return \sodium_crypto_box_keypair();
6✔
31
    }
32

33
    /**
34
     * Makes a box nonce with the correct length.
35
     *
36
     * @throws Exception if fail to get random bytes
37
     *
38
     * @return string
39
     */
40
    public static function makeNonce() : string
41
    {
42
        return \random_bytes(\SODIUM_CRYPTO_BOX_NONCEBYTES);
4✔
43
    }
44

45
    /**
46
     * Makes the secret key from a keypair.
47
     *
48
     * @param string $keyPair
49
     *
50
     * @see BoxTrait::makeKeyPair()
51
     *
52
     * @throws SodiumException
53
     *
54
     * @return string
55
     */
56
    public static function makeSecretKey(#[SensitiveParameter] string $keyPair) : string
57
    {
58
        return \sodium_crypto_box_secretkey($keyPair);
4✔
59
    }
60

61
    /**
62
     * Makes the public key from a keypair.
63
     *
64
     * @param string $keyPair
65
     *
66
     * @see BoxTrait::makeKeyPair()
67
     *
68
     * @throws SodiumException
69
     *
70
     * @return string
71
     */
72
    public static function makePublicKey(#[SensitiveParameter] string $keyPair) : string
73
    {
74
        return \sodium_crypto_box_publickey($keyPair);
5✔
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc