Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkeash committed Oct 31, 2017
1 parent 7774f02 commit f7b9764
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/Box.php
Expand Up @@ -28,17 +28,14 @@ public function verify(Request $request, Collection $config): bool
$generated = $request->getContent() . $rawTimestamp;

// Primary or Secondary can pass to be valid.
$encoded = base64_encode(hash_hmac('sha256', $generated, $config->get('primary'), true));
if (hash_equals($encoded, $request->header('BOX-SIGNATURE-PRIMARY'))) {
return true;
}
return $this->check($generated, $config->get('primary'), $request->header('BOX-SIGNATURE-PRIMARY')) || $this->check($generated, $config->get('secondary'), $request->header('BOX-SIGNATURE-SECONDARY'));
}

$encoded = base64_encode(hash_hmac('sha256', $generated, $config->get('secondary'), true));
if (hash_equals($encoded, $request->header('BOX-SIGNATURE-SECONDARY'))) {
return true;
}
public function check($generated, $key, $supplied)
{
$encoded = base64_encode(hash_hmac('sha256', $generated, $key, true));

return false;
return hash_equals($encoded, $supplied);
}

public function headers(): array
Expand Down

0 comments on commit f7b9764

Please sign in to comment.