Skip to content

Commit

Permalink
typo
Browse files Browse the repository at this point in the history
  • Loading branch information
achretien committed Jan 14, 2025
1 parent ad4831c commit 5930c69
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/SigningString.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ private function headerValue(string $name): string

$header = '';
$values = $this->message->getHeader($name);
while (sizeof($values) > 0) {
while (count($values) > 0) {
$header = $header.$values[0];
array_shift($values);
if (sizeof($values) > 0) {
if (count($values) > 0) {
$header = $header.', ';
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Verification.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ public function __construct(private readonly RequestInterface $message, private
// This will permit e.g. Authorization: Bearer to co-exist with Authorization: Signature
switch (strtolower($header)) {
case 'signature':
if (0 == sizeof($message->getHeader('Signature'))) {
if (0 == count($message->getHeader('Signature'))) {
throw new HeaderException("Cannot locate header 'Signature'");
} elseif (sizeof($message->getHeader('Signature')) > 1) {
} elseif (count($message->getHeader('Signature')) > 1) {
throw new HeaderException("Multiple headers named 'Signature'");
}
$signatureLine = $message->getHeader('Signature')[0];
break;
case 'authorization':
if (0 == sizeof($message->getHeader('Authorization'))) {
if (0 == count($message->getHeader('Authorization'))) {
throw new HeaderException("Cannot locate header 'Authorization'");
} elseif (sizeof($message->getHeader('Authorization')) > 1) {
} elseif (count($message->getHeader('Authorization')) > 1) {
throw new HeaderException("Multiple headers named 'Authorization'");
}
$authorizationType = explode(' ', $message->getHeader('Authorization')[0])[0];
Expand Down
70 changes: 27 additions & 43 deletions src/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,24 @@ public function isSigned(RequestInterface $message): bool
try {
$verification = new Verification($message, $this->keyStore, 'Signature');
$result = $verification->verify();
$this->status[] =
"Message SigningString: '".
base64_encode($verification->getSigningString()).
"'";
if ($result) {
$this->status[] = "Message SigningString: '".base64_encode($verification->getSigningString())."'";
}

return $result;
} catch (HeaderException) {
$this->status[] = 'Signature header not found';
} catch (SignatureParseException) {
$this->status[] = 'Signature header malformed';
} catch (SignedHeaderNotPresentException|KeyStoreException|SignatureException $e) {
$this->status[] = $e->getMessage();
} catch (Exception $e) {
// TODO: Match at least one header
switch (get_class($e)) {
case 'HttpSignatures\HeaderException':
$this->status[] = 'Signature header not found';

return false;
case 'HttpSignatures\SignatureParseException':
$this->status[] = 'Signature header malformed';

return false;
case 'HttpSignatures\SignedHeaderNotPresentException':
case 'HttpSignatures\KeyStoreException':
case 'HttpSignatures\SignatureException':
$this->status[] = $e->getMessage();

return false;
default:
$this->status[] = 'Unknown exception '.get_class($e).': '.$e->getMessage();
throw $e;
}
$this->status[] = 'Unknown exception '.get_class($e).': '.$e->getMessage();

throw $e;
}

return false;
}

/**
Expand All @@ -60,34 +50,28 @@ public function isAuthorized(RequestInterface $message): bool
try {
$verification = new Verification($message, $this->keyStore, 'Authorization');
$result = $verification->verify();
$this->status[] =
"Message SigningString: '".
base64_encode($verification->getSigningString()).
"'";
if ($result) {
$this->status[] = "Message SigningString: '".base64_encode($verification->getSigningString())."'";
}

return $result;
} catch (HeaderException) {
$this->status[] = 'Authorization header not found';
} catch (SignatureParseException) {
$this->status[] = 'Authorization header malformed';
} catch (Exception $e) {
// TODO: Match at least one header
switch (get_class($e)) {
case 'HttpSignatures\HeaderException':
$this->status[] = 'Authorization header not found';

return false;
case 'HttpSignatures\SignatureParseException':
$this->status[] = 'Authorization header malformed';

return false;
default:
$this->status[] = 'Unknown exception '.get_class($e).': '.$e->getMessage();
throw $e;
}
$this->status[] = 'Unknown exception '.get_class($e).': '.$e->getMessage();

throw $e;
}

return false;
}

public function isValidDigest(RequestInterface $message): bool
{
$this->status = [];
if (0 == sizeof($message->getHeader('Digest'))) {
if (0 == count($message->getHeader('Digest'))) {
$this->status[] = 'Digest header not found';

return false;
Expand Down

0 comments on commit 5930c69

Please sign in to comment.