Skip to content

Commit

Permalink
Memoise Key::getThumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinmo committed Aug 27, 2023
1 parent 717c82e commit 305ea66
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/SimpleJWT/Keys/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,20 @@ abstract protected function getThumbnailMembers();
/**
* {@inheritdoc}
*/
public function getThumbnail() {
$members = $this->getThumbnailMembers();
$signing = [];
foreach ($members as $member) $signing[$member] = strval($this->data[$member]);
ksort($signing);
$hash_input = json_encode($signing);
if ($hash_input == false) throw new KeyException('Cannot generate thumbnail');
return Util::base64url_encode(hash('sha256', $hash_input, true));
public final function getThumbnail() {
static $thumbnail = null;

if ($thumbnail == null) {
$members = $this->getThumbnailMembers();
$signing = [];
foreach ($members as $member) $signing[$member] = strval($this->data[$member]);
ksort($signing);
$hash_input = json_encode($signing);
if ($hash_input == false) throw new KeyException('Cannot generate thumbnail');
$thumbnail = Util::base64url_encode(hash('sha256', $hash_input, true));
}

return $thumbnail;
}

/**
Expand Down

0 comments on commit 305ea66

Please sign in to comment.