Issues (341)

src/XML/Utils/Random.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\Utils;
6
7
use function bin2hex;
8
use function random_bytes;
9
10
/**
11
 * @package simplesamlphp/xml-common
12
 */
13
class Random
14
{
15
    /**
16
     * The fixed length of random identifiers.
17
     *
18
     * (43 - 1) / 2 = 21 → random_bytes(21) → 168 bits
19
     */
20
    public const int ID_LENGTH = 43;
0 ignored issues
show
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 20 at column 21
Loading history...
21
22
23
    /**
24
     * This function will generate a unique ID that is valid for use
25
     * in an xs:ID attribute
26
     */
27
    public function generateID(): string
28
    {
29
        return '_' . bin2hex(random_bytes((self::ID_LENGTH - 1) / 2));
30
    }
31
}
32