| @@ -65,8 +65,9 @@ | ||
| 65 | 65 | * |
| 66 | 66 | * @return array The values needed to construct a signed URL or cookie |
| 67 | 67 | * @throws \InvalidArgumentException when not provided either a policy or a |
| 68 | 68 | * resource and a expires |
| 69 | + * @throws \RuntimeException when generated signature is empty | |
| 69 | 70 | * |
| 70 | 71 | * @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-cookies.html |
| 71 | 72 | */ |
| 72 | 73 | public function getSignature($resource = null, $expires = null, $policy = null) |
| @@ -93,9 +94,19 @@ | ||
| 93 | 94 | } |
| 94 | 95 | private function sign($policy) |
| 95 | 96 | { |
| 96 | 97 | $signature = ''; |
| 97 | - \openssl_sign($policy, $signature, $this->pkHandle); | |
| 98 | + if (!\openssl_sign($policy, $signature, $this->pkHandle)) { | |
| 99 | + $errorMessages = []; | |
| 100 | + while (($newMessage = \openssl_error_string()) !== \false) { | |
| 101 | + $errorMessages[] = $newMessage; | |
| 102 | + } | |
| 103 | + $exceptionMessage = "An error has occurred when signing the policy"; | |
| 104 | + if (\count($errorMessages) > 0) { | |
| 105 | + $exceptionMessage = \implode("\n", $errorMessages); | |
| 106 | + } | |
| 107 | + throw new \RuntimeException($exceptionMessage); | |
| 108 | + } | |
| 98 | 109 | return $signature; |
| 99 | 110 | } |
| 100 | 111 | private function encode($policy) |
| 101 | 112 | { |