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

aplus-framework / crypto / 11228560566

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

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/Sign.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 SensitiveParameter;
13
use SodiumException;
14

15
/**
16
 * Class Sign.
17
 *
18
 * @package crypto
19
 */
20
class Sign
21
{
22
    /**
23
     * Makes a keypair.
24
     *
25
     * @throws SodiumException
26
     *
27
     * @return string
28
     */
29
    public static function makeKeyPair() : string
30
    {
31
        return \sodium_crypto_sign_keypair();
3✔
32
    }
33

34
    /**
35
     * Makes the secret key from a keypair.
36
     *
37
     * @param string $keyPair
38
     *
39
     * @see Sign::makeKeyPair()
40
     *
41
     * @throws SodiumException
42
     *
43
     * @return string
44
     */
45
    public static function makeSecretKey(#[SensitiveParameter] string $keyPair) : string
46
    {
47
        return \sodium_crypto_sign_secretkey($keyPair); // @phpstan-ignore-line
2✔
48
    }
49

50
    /**
51
     * Makes the public key from a keypair.
52
     *
53
     * @param string $keyPair
54
     *
55
     * @see Sign::makeKeyPair()
56
     *
57
     * @throws SodiumException
58
     *
59
     * @return string
60
     */
61
    public static function makePublicKey(#[SensitiveParameter] string $keyPair) : string
62
    {
63
        return \sodium_crypto_sign_publickey($keyPair); // @phpstan-ignore-line
2✔
64
    }
65

66
    /**
67
     * Gets the digital signature (detached) from a message with a secret key.
68
     *
69
     * @param string $message
70
     * @param string $secretKey
71
     *
72
     * @see Sign::makeSecretKey()
73
     *
74
     * @throws SodiumException
75
     *
76
     * @return string
77
     */
78
    public static function signature(
79
        #[SensitiveParameter]
80
        string $message,
81
        #[SensitiveParameter]
82
        string $secretKey
83
    ) : string {
84
        return \sodium_crypto_sign_detached($message, $secretKey); // @phpstan-ignore-line
1✔
85
    }
86

87
    /**
88
     * Verifies if a message has a valid signature.
89
     *
90
     * @param string $message
91
     * @param string $signature
92
     * @param string $publicKey
93
     *
94
     * @see Sign::makePublicKey()
95
     * @see Sign::signature()
96
     *
97
     * @throws SodiumException
98
     *
99
     * @return bool
100
     */
101
    public static function verify(
102
        #[SensitiveParameter]
103
        string $message,
104
        #[SensitiveParameter]
105
        string $signature,
106
        #[SensitiveParameter]
107
        string $publicKey
108
    ) : bool {
109
        return \sodium_crypto_sign_verify_detached($signature, $message, $publicKey); // @phpstan-ignore-line
1✔
110
    }
111
}
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