Skip to content

Commit

Permalink
Fixed Client::getCertificatesBySerialNumber() when searching not for …
Browse files Browse the repository at this point in the history
…the first entry
  • Loading branch information
MaximilianKresse committed Mar 16, 2022
1 parent 8e0ef11 commit e320e73
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/demo-ltv.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
$settings['username'],
$settings['activationPin']
);
// These information should be cached
// This information should be cached
$certificates = $client->getCertificatesBySerialNumber($certificateSerialNumber);
$certificate = new SetaPDF_Signer_X509_Certificate($certificates['certificate']);

Expand Down
10 changes: 5 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getCertificatesBySerialNumber(string $certificateSerialNumber):
{
$certificates = $this->getCertificates();
// search for the correct certificate chain
$certificateChain = \array_filter(
$certificateChain = \current(\array_filter(
$certificates,
static function ($certificateChain) use ($certificateSerialNumber) {
foreach ($certificateChain as $certificate) {
Expand All @@ -120,20 +120,20 @@ static function ($certificateChain) use ($certificateSerialNumber) {
}
return false;
}
)[0] ?? null;
if ($certificateChain === null) {
));
if ($certificateChain === false) {
throw new Exception(\sprintf(
'Certificate with serial number "%s" not found.',
$certificateSerialNumber
));
}

$mainCertificate = \array_filter(
$mainCertificate = \current(\array_filter(
$certificateChain,
static function ($certificate) use ($certificateSerialNumber) {
return $certificate['certificateSerialNumber'] === $certificateSerialNumber;
}
)[0] ?? null;
));

$extraCertificates = \array_filter($certificateChain, static function ($certificate) {
return $certificate['level'] !== 'USER';
Expand Down

0 comments on commit e320e73

Please sign in to comment.