-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a separate class to respresent SAML artifacts
- Loading branch information
Showing
2 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\SAML2; | ||
|
||
use SimpleSAML\Assert\Assert; | ||
|
||
use function base64_decode; | ||
use function bin2hex; | ||
use function bindec; | ||
use function substr; | ||
|
||
/** | ||
* Class for SAML artifacts. | ||
* | ||
* @package simplesamlphp/saml2 | ||
*/ | ||
final class Artifact | ||
{ | ||
/** | ||
* Initialize an artifact. | ||
* | ||
* @param string $artifact | ||
* @param int $endpointIndex | ||
* @param string $sourceId | ||
*/ | ||
public function __construct( | ||
protected string $samlArt, | ||
protected int $endpointIndex, | ||
protected string $sourceId, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the artifact-property | ||
* | ||
* @return string | ||
*/ | ||
public function getArtifact(): string | ||
{ | ||
return $this->artifact; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the endpointIndex-property | ||
* | ||
* @return int | ||
*/ | ||
public function getEndpointIndex(): int | ||
{ | ||
return $this->endpointIndex; | ||
} | ||
|
||
|
||
/** | ||
* Collect the value of the sourceId-property | ||
* | ||
* @return string | ||
*/ | ||
public function getSourceId(): string | ||
{ | ||
return $this->sourceId; | ||
} | ||
|
||
|
||
/** | ||
* Instantiate an Artifact from a SAMLart query parameter | ||
*/ | ||
public static function fromQuery(string $samlArt): static | ||
{ | ||
Assert::stringPlausibleBase64($samlArt); | ||
|
||
$artifact = base64_decode($samlArt, true); | ||
$endpointIndex = bindec(substr($artifact, 2, 2)); | ||
$sourceId = bin2hex(substr($artifact, 4, 20)); | ||
|
||
return new static($artifact, $endpointIndex, $sourceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters