RequestValidator.php
Current file: /Users/kevin/code/twilio-php/Services/Twilio/RequestValidator.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
100.00% 1 / 1
100.00% 3 / 3 CRAP
100.00% 8 / 8
Services_Twilio_RequestValidator
100.00% 1 / 1
100.00% 3 / 3 4
100.00% 8 / 8
 __construct($token)
100.00% 1 / 1 1
100.00% 2 / 2
 computeSignature($url, $data = array()
100.00% 1 / 1 2
100.00% 4 / 4
 validate($expectedSignature, $url, $data = array()
100.00% 1 / 1 1
100.00% 2 / 2


       1                 : <?php                                                                         
       2                 :                                                                               
       3                 : class Services_Twilio_RequestValidator                                        
       4                 : {                                                                             
       5                 :                                                                               
       6                 :     protected $AuthToken;                                                     
       7                 :                                                                               
       8                 :     function __construct($token)                                              
       9                 :     {                                                                         
      10               1 :         $this->AuthToken = $token;                                            
      11               1 :     }                                                                         
      12                 :                                                                               
      13                 :     public function computeSignature($url, $data = array())                   
      14                 :     {                                                                         
      15                 :         // sort the array by keys                                             
      16               1 :         ksort($data);                                                         
      17                 :                                                                               
      18                 :         // append them to the data string in order                            
      19                 :         // with no delimiters                                                 
      20               1 :         foreach($data as $key => $value)                                      
      21               1 :             $url .= "$key$value";                                             
      22                 :                                                                               
      23                 :         // This function calculates the HMAC hash of the data with the key    
      24                 :         // passed in                                                          
      25                 :         // Note: hash_hmac requires PHP 5 >= 5.1.2 or PECL hash:1.1-1.5       
      26                 :         // Or http://pear.php.net/package/Crypt_HMAC/                         
      27               1 :         return base64_encode(hash_hmac("sha1", $url, $this->AuthToken, true));
      28                 :     }                                                                         
      29                 :                                                                               
      30                 :     public function validate($expectedSignature, $url, $data = array())       
      31                 :     {                                                                         
      32               1 :         return $this->computeSignature($url, $data)                           
      33               1 :             == $expectedSignature;                                            
      34                 :     }                                                                         
      35                 :                                                                               

Generated by PHP_CodeCoverage 1.1.2 using PHP 5.3.13 and PHPUnit 3.6.11 at Mon Jun 4 22:46:14 PDT 2012.