LTI Integration Library  3.1.0
PHP class library for building LTI integrations
OAuthSignatureMethod.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ceLTIc\LTI\OAuth;
4 
17 abstract class OAuthSignatureMethod
18 {
19 
24  abstract public function get_name();
25 
36  abstract public function build_signature($request, $consumer, $token);
37 
46  public function check_signature($request, $consumer, $token, $signature)
47  {
48  $built = $this->build_signature($request, $consumer, $token);
49 
50  // Check for zero length, although unlikely here
51  if (strlen($built) == 0 || strlen($signature) == 0) {
52  return false;
53  }
54 
55  if (strlen($built) != strlen($signature)) {
56  return false;
57  }
58 
59  // Avoid a timing leak with a (hopefully) time insensitive compare
60  $result = 0;
61  for ($i = 0; $i < strlen($signature); $i++) {
62  $result |= ord($built{$i}) ^ ord($signature{$i});
63  }
64 
65  return $result == 0;
66  }
67 
68 }
Class to represent an OAuth Signature Method.
build_signature($request, $consumer, $token)
Build up the signature NOTE: The output of this function MUST NOT be urlencoded.
check_signature($request, $consumer, $token, $signature)
Verifies that a given signature is correct.
get_name()
Needs to return the name of the Signature Method (ie HMAC-SHA1)