Skip to content

Commit

Permalink
Add exception when signature generation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
DocLM committed Dec 5, 2022
1 parent 28daf91 commit ce21d37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changes/nextrelease
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "enhancement",
"category": "CloudFront",
"description": "Throw exception when an empty signature for signed url is generated."
}
]
9 changes: 9 additions & 0 deletions src/CloudFront/Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function __destruct()
* @return array The values needed to construct a signed URL or cookie
* @throws \InvalidArgumentException when not provided either a policy or a
* resource and a expires
* @throws \RuntimeException when generated signature is empty
*
* @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-cookies.html
*/
Expand Down Expand Up @@ -115,6 +116,14 @@ private function sign($policy)
$signature = '';
openssl_sign($policy, $signature, $this->pkHandle);

if(empty($signature)) {
$errorMessages = [];
while(($newMessage = openssl_error_string()) !== false){
$errorMessages[] = $newMessage;
}
throw new \RuntimeException(implode("\n",$errorMessages));
}

return $signature;
}

Expand Down

0 comments on commit ce21d37

Please sign in to comment.