Skip to content

Commit

Permalink
Add ability to dependency inject Base64UrlDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekman committed Feb 7, 2019
1 parent 88fd0e2 commit 6f5746c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/JWKConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
class JWKConverter
{

/** @var Base64UrlDecoder */
private $base64UrlDecoder;

public function __construct(?Base64UrlDecoder $base64UrlDecoder = null)
{
$this->base64UrlDecoder = $base64UrlDecoder ?? new Base64UrlDecoder();
}

/**
* @param array $jwk
* @return string
Expand All @@ -40,11 +48,10 @@ public function toPEM(array $jwk): string
}

$rsa = new RSA();
$base64UrlDecoder = new Base64UrlDecoder();
$rsa->loadKey(
[
'e' => new BigInteger(base64_decode($jwk['e']), 256),
'n' => new BigInteger($base64UrlDecoder->decode($jwk['n']), 256)
'n' => new BigInteger($this->base64UrlDecoder->decode($jwk['n']), 256)
]
);
return $rsa->getPublicKey();
Expand Down

0 comments on commit 6f5746c

Please sign in to comment.