You are here

public static function Braintree_Digest::secureCompare in Commerce Braintree 7

1 call to Braintree_Digest::secureCompare()
Braintree_WebhookNotification::_validateSignature in braintree_php/lib/Braintree/WebhookNotification.php

File

braintree_php/lib/Braintree/Digest.php, line 24

Class

Braintree_Digest
Digest creates an HMAC-SHA1 hash for encrypting messages

Code

public static function secureCompare($left, $right) {
  if (strlen($left) != strlen($right)) {
    return false;
  }
  $leftBytes = unpack("C*", $left);
  $rightBytes = unpack("C*", $right);
  $result = 0;
  for ($i = 0; $i < strlen($left); $i++) {
    $result = $result | $left[$i] ^ $right[$i];
  }
  return $result == 0;
}