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

NexusPHP / framework / 12657354225

07 Jan 2025 06:43PM UTC coverage: 100.0%. Remained the same
12657354225

Pull #8

github

web-flow
Merge 84ab458a9 into 8baacd33d
Pull Request #8: Implement Nexus Encryption v2

35 of 35 new or added lines in 12 files covered. (100.0%)

993 of 993 relevant lines covered (100.0%)

7.95 hits per line

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

100.0
/src/Nexus/Encryption/Cryptex.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of the Nexus framework.
7
 *
8
 * (c) John Paul E. Balandan, CPA <paulbalandan@gmail.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Nexus\Encryption;
15

16
use Nexus\Encryption\Exception\InvalidEncodingVariantException;
17

18
final readonly class Cryptex
19
{
20
    /**
21
     * Version tag in the form 'v' + major + minor + patch.
22
     *
23
     * Note: Increment only the major and minor versions when making updates.
24
     */
25
    public const string HEADER_VERSION = "\x76\x01\x00\x00";
26

27
    /**
28
     * Length of the version header.
29
     */
30
    public const int HEADER_VERSION_SIZE = 4;
31

32
    public const int ENCODE_NONE = 0;
33
    public const int ENCODE_BASE64_ORIGINAL = 1;
34
    public const int ENCODE_BASE64_ORIGINAL_NO_PADDING = 2;
35
    public const int ENCODE_BASE64_URL_SAFE = 3;
36
    public const int ENCODE_BASE64_URL_SAFE_NO_PADDING = 4;
37
    public const int ENCODE_HEX = 5;
38

39
    /**
40
     * Gets the encoder. If `self::ENCODE_NONE` is chosen, any subsequent encode
41
     * and decode operations will just return the strings as-is.
42
     *
43
     * @throws InvalidEncodingVariantException
44
     */
45
    public static function encoder(int $variant = self::ENCODE_HEX): Encoding\EncoderInterface
46
    {
47
        return match ($variant) {
14✔
48
            self::ENCODE_NONE => new Encoding\NullEncoder(),
2✔
49
            self::ENCODE_BASE64_ORIGINAL => new Encoding\Base64OriginalEncoder(),
2✔
50
            self::ENCODE_BASE64_ORIGINAL_NO_PADDING => new Encoding\Base64OriginalNoPaddingEncoder(),
2✔
51
            self::ENCODE_BASE64_URL_SAFE => new Encoding\Base64UrlSafeEncoder(),
2✔
52
            self::ENCODE_BASE64_URL_SAFE_NO_PADDING => new Encoding\Base64UrlSafeNoPaddingEncoder(),
2✔
53
            self::ENCODE_HEX => new Encoding\HexEncoder(),
2✔
54
            default => throw new InvalidEncodingVariantException(),
14✔
55
        };
14✔
56
    }
57
}
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