Skip to content

Commit

Permalink
Ease sharing keys
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Mar 2, 2017
1 parent 741191e commit b0d9982
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 1 addition & 5 deletions Services/KeyLoader/KeyDumperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader;

/**
* Interface for classes that are able to load crypto keys.
*
* @author Robin Chalas <[email protected]>
*/
interface KeyDumperInterface
{
/**
* Dumps a key as sharable s
*
* @param resource|string
* Dumps a key to be shared between parties.
*
* @return resource|string
*/
Expand Down
16 changes: 15 additions & 1 deletion Services/KeyLoader/OpenSSLKeyLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Robin Chalas <[email protected]>
*/
class OpenSSLKeyLoader extends AbstractKeyLoader
class OpenSSLKeyLoader extends AbstractKeyLoader implements KeyDumperInterface
{
/**
* {@inheritdoc}
Expand All @@ -32,4 +32,18 @@ public function loadKey($type)

return $key;
}

/**
* {@inheritdoc}
*/
public function dumpKey()
{
$key = openssl_pkey_get_details($this->loadKey('public'));

if (!isset($key['key'])) {
return;
}

return $key['key'];
}
}
10 changes: 9 additions & 1 deletion Services/KeyLoader/RawKeyLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @author Robin Chalas <[email protected]>
*/
class RawKeyLoader extends AbstractKeyLoader
class RawKeyLoader extends AbstractKeyLoader implements KeyDumperInterface
{
/**
* @param string $type
Expand All @@ -20,4 +20,12 @@ public function loadKey($type)
{
return file_get_contents($this->getKeyPath($type));
}

/**
* {@inheritdoc}
*/
public function dumpKey()
{
return $this->loadKey('public');
}
}

0 comments on commit b0d9982

Please sign in to comment.