-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from misantron/issue-207-patch
Add content check after key file reading
- Loading branch information
Showing
2 changed files
with
26 additions
and
7 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 |
---|---|---|
|
@@ -7,7 +7,9 @@ | |
|
||
namespace Lcobucci\JWT\Signer; | ||
|
||
use Exception; | ||
use InvalidArgumentException; | ||
use SplFileObject; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
|
@@ -54,17 +56,17 @@ private function setContent($content) | |
* | ||
* @return string | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws InvalidArgumentException | ||
*/ | ||
private function readFile($content) | ||
{ | ||
$file = substr($content, 7); | ||
try { | ||
$file = new SplFileObject(substr($content, 7)); | ||
|
||
if (!is_readable($file)) { | ||
throw new \InvalidArgumentException('You must inform a valid key file'); | ||
return $file->fread($file->getSize()); | ||
} catch (Exception $exception) { | ||
throw new InvalidArgumentException('You must inform a valid key file', 0, $exception); | ||
} | ||
|
||
return file_get_contents($file); | ||
} | ||
|
||
/** | ||
|
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