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

azjezz / psl / 22639996882

03 Mar 2026 07:52PM UTC coverage: 98.092% (-0.1%) from 98.201%
22639996882

Pull #607

github

azjezz
use fcc

Signed-off-by: azjezz <azjezz@protonmail.com>
Pull Request #607: feat: introduce `Crypto` component

350 of 367 new or added lines in 42 files covered. (95.37%)

2 existing lines in 1 file now uncovered.

9304 of 9485 relevant lines covered (98.09%)

39.15 hits per line

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

95.45
/src/Psl/Crypto/Aead/encrypt.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Psl\Crypto\Aead;
6

7
use Psl\Crypto\Exception;
8
use Psl\Crypto\Internal;
9
use SensitiveParameter;
10

11
use function sodium_crypto_aead_aes256gcm_encrypt;
12
use function sodium_crypto_aead_aes256gcm_is_available;
13
use function sodium_crypto_aead_chacha20poly1305_ietf_encrypt;
14
use function sodium_crypto_aead_xchacha20poly1305_ietf_encrypt;
15

16
/**
17
 * Encrypt a plaintext message using AEAD with an explicit nonce.
18
 *
19
 * @throws Exception\RuntimeException If encryption fails or AES-256-GCM is not available.
20
 */
21
function encrypt(
22
    #[SensitiveParameter] string $plaintext,
23
    #[SensitiveParameter] Key $key,
24
    #[SensitiveParameter] string $nonce,
25
    string $additional_data,
26
    Algorithm $algorithm,
27
): string {
28
    return match ($algorithm) {
29
        Algorithm::Aes256Gcm => (static function () use ($plaintext, $key, $nonce, $additional_data): string {
14✔
30
            if (!sodium_crypto_aead_aes256gcm_is_available()) {
1✔
NEW
31
                throw new Exception\RuntimeException('AES-256-GCM is not available on this platform.');
×
32
            }
33

34
            return Internal\call_sodium(fn() => sodium_crypto_aead_aes256gcm_encrypt(
1✔
35
                $plaintext,
1✔
36
                $additional_data,
1✔
37
                $nonce,
1✔
38
                $key->bytes,
1✔
39
            ));
1✔
40
        })(),
14✔
41
        Algorithm::XChaCha20Poly1305 => Internal\call_sodium(fn() => sodium_crypto_aead_xchacha20poly1305_ietf_encrypt(
13✔
42
            $plaintext,
13✔
43
            $additional_data,
13✔
44
            $nonce,
13✔
45
            $key->bytes,
13✔
46
        )),
13✔
47
        Algorithm::ChaCha20Poly1305 => Internal\call_sodium(fn() => sodium_crypto_aead_chacha20poly1305_ietf_encrypt(
14✔
48
            $plaintext,
14✔
49
            $additional_data,
14✔
50
            $nonce,
14✔
51
            $key->bytes,
14✔
52
        )),
14✔
53
    };
54
}
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

© 2026 Coveralls, Inc