Skip to content

Commit f63f597

Browse files
committed
Add local SAML2-compliant version of the Random ID-generator
1 parent 4ea1aee commit f63f597

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Example:
5959
// Create Issuer
6060
$issuer = new \SimpleSAML\SAML2\XML\saml\Issuer('https://sp.example.edu');
6161

62-
// Instantiate XML Random utils
63-
$randomUtils = new \SimpleSAML\XML\Utils\Random();
62+
// Instantiate SAML2 Random utils
63+
$randomUtils = new \SimpleSAML\SAML2\Utils\Random();
6464

6565
// Set up an AuthnRequest
6666
$request = new \SimpleSAML\SAML2\XML\samlp\AuthnRequest(

src/Utils/Random.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/saml2
12+
*/
13+
class Random extends \SimpleSAML\XML\Utils\Random
14+
{
15+
/**
16+
* The fixed length of random identifiers.
17+
*
18+
* This results in the maximum of 160 bits entropy specified in paragraph 1.3.4 of the SAML 2.0 core specifications
19+
*
20+
* (41 - 1) / 2 = 20 → random_bytes(20) → 160 bits
21+
*/
22+
public const int ID_LENGTH = 41;
23+
}

0 commit comments

Comments
 (0)