Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Input method implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Morselli committed Oct 8, 2015
1 parent 5b8b7e5 commit 421077f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"require": {
"php": ">=5.6",
"lib-openssl": "*",
"spomky-labs/jose-interface": "~2.2.1",
"spomky-labs/jose-interface": "~2.3.0",
"spomky-labs/pbkdf2": "~1.0",
"mdanter/ecc": "0.3",
"spomky-labs/aes-key-wrap": "~2.0",
Expand Down
25 changes: 25 additions & 0 deletions lib/JWable.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ trait JWable
*/
protected $encoded_protected_header = '';

/**
* @var string
*/
protected $input = null;

/**
* @var string
*/
Expand Down Expand Up @@ -49,6 +54,14 @@ public function getEncodedProtectedHeader()
return $this->encoded_protected_header;
}

/**
* @return string|null
*/
public function getInput()
{
return $this->input;
}

/**
* @return string
*/
Expand Down Expand Up @@ -80,6 +93,18 @@ public function getPayload()
return $this->payload;
}

/**
* @param string $input
*
* @return self
*/
public function setInput($input)
{
$this->input = $input;

return $this;
}

/**
* @param string $encoded_protected_header
*
Expand Down
21 changes: 13 additions & 8 deletions lib/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public function load($input)
$json = Converter::convert($input, JSONSerializationModes::JSON_SERIALIZATION, false);
if (is_array($json)) {
if (array_key_exists('signatures', $json)) {
return $this->loadSerializedJsonJWS($json);
return $this->loadSerializedJsonJWS($json, $input);
}
if (array_key_exists('recipients', $json)) {
return $this->loadSerializedJsonJWE($json);
return $this->loadSerializedJsonJWE($json, $input);
}
}
throw new \InvalidArgumentException('Unable to load the input');
Expand Down Expand Up @@ -150,11 +150,12 @@ public function verify(JWTInterface $jwt)
}

/**
* @param array $data
* @param array $data
* @param string $input
*
* @return \Jose\JWSInterface|\Jose\JWSInterface[]
*/
protected function loadSerializedJsonJWS(array $data)
protected function loadSerializedJsonJWS(array $data, $input)
{
$encoded_payload = isset($data['payload']) ? $data['payload'] : '';
$payload = Base64Url::decode($encoded_payload);
Expand All @@ -170,7 +171,9 @@ protected function loadSerializedJsonJWS(array $data)
}
$unprotected_header = isset($signature['header']) ? $signature['header'] : [];

$jws[] = $this->createJWS($encoded_protected_header, $encoded_payload, $protected_header, $unprotected_header, $payload, Base64Url::decode($signature['signature']));
$result = $this->createJWS($encoded_protected_header, $encoded_payload, $protected_header, $unprotected_header, $payload, Base64Url::decode($signature['signature']));
$result->setInput($input);
$jws[] = $result;
}

return count($jws) > 1 ? $jws : current($jws);
Expand Down Expand Up @@ -281,11 +284,12 @@ public function decryptCEK(JWAInterface $key_encryption_algorithm, ContentEncryp
}

/**
* @param array $data
* @param array $data
* @param string $input
*
* @return \Jose\JWEInterface|\Jose\JWEInterface[]
*/
protected function loadSerializedJsonJWE(array $data)
protected function loadSerializedJsonJWE(array $data, $input)
{
$result = [];
foreach ($data['recipients'] as $recipient) {
Expand All @@ -302,7 +306,8 @@ protected function loadSerializedJsonJWE(array $data)
->setTag(array_key_exists('tag', $data) ? Base64Url::decode($data['tag']) : null)
->setProtectedHeader($protected_header)
->setEncodedProtectedHeader($encoded_protected_header)
->setUnprotectedHeader(array_merge($unprotected_header, $header));
->setUnprotectedHeader(array_merge($unprotected_header, $header))
->setInput($input);
$result[] = $jwe;
}

Expand Down

0 comments on commit 421077f

Please sign in to comment.