• 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/Utils.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 SodiumException;
13

14
/**
15
 * Class Utils.
16
 *
17
 * @package crypto
18
 */
19
class Utils
20
{
21
    /**
22
     * Converts a binary string to hexadecimal.
23
     *
24
     * @param string $string
25
     *
26
     * @throws SodiumException
27
     *
28
     * @return string The hexadecimal string
29
     */
30
    public static function bin2hex(string $string) : string
31
    {
32
        return \sodium_bin2hex($string);
1✔
33
    }
34

35
    /**
36
     * Converts a hexadecimal string to binary.
37
     *
38
     * @param string $string
39
     * @param string $ignore
40
     *
41
     * @throws SodiumException
42
     *
43
     * @return string The binary string
44
     */
45
    public static function hex2bin(string $string, string $ignore = '') : string
46
    {
47
        return \sodium_hex2bin($string, $ignore);
1✔
48
    }
49

50
    /**
51
     * Converts a base64 string to binary.
52
     *
53
     * @param string $string
54
     * @param int $id
55
     * @param string $ignore
56
     *
57
     * @throws SodiumException
58
     *
59
     * @return string The binary string
60
     */
61
    public static function base642bin(
62
        string $string,
63
        int $id = \SODIUM_BASE64_VARIANT_ORIGINAL,
64
        string $ignore = ''
65
    ) : string {
66
        return \sodium_base642bin($string, $id, $ignore);
2✔
67
    }
68

69
    /**
70
     * Converts a binary string to base64.
71
     *
72
     * @param string $string
73
     * @param int $id
74
     *
75
     * @throws SodiumException
76
     *
77
     * @return string The base64 encoded string
78
     */
79
    public static function bin2base64(
80
        string $string,
81
        int $id = \SODIUM_BASE64_VARIANT_ORIGINAL,
82
    ) : string {
83
        return \sodium_bin2base64($string, $id);
2✔
84
    }
85
}
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