comparison vendor/symfony/http-kernel/UriSigner.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
45 { 45 {
46 $url = parse_url($uri); 46 $url = parse_url($uri);
47 if (isset($url['query'])) { 47 if (isset($url['query'])) {
48 parse_str($url['query'], $params); 48 parse_str($url['query'], $params);
49 } else { 49 } else {
50 $params = array(); 50 $params = [];
51 } 51 }
52 52
53 $uri = $this->buildUrl($url, $params); 53 $uri = $this->buildUrl($url, $params);
54 $params[$this->parameter] = $this->computeHash($uri);
54 55
55 return $uri.(false === strpos($uri, '?') ? '?' : '&').$this->parameter.'='.$this->computeHash($uri); 56 return $this->buildUrl($url, $params);
56 } 57 }
57 58
58 /** 59 /**
59 * Checks that a URI contains the correct hash. 60 * Checks that a URI contains the correct hash.
60 * 61 *
66 { 67 {
67 $url = parse_url($uri); 68 $url = parse_url($uri);
68 if (isset($url['query'])) { 69 if (isset($url['query'])) {
69 parse_str($url['query'], $params); 70 parse_str($url['query'], $params);
70 } else { 71 } else {
71 $params = array(); 72 $params = [];
72 } 73 }
73 74
74 if (empty($params[$this->parameter])) { 75 if (empty($params[$this->parameter])) {
75 return false; 76 return false;
76 } 77 }
77 78
78 $hash = urlencode($params[$this->parameter]); 79 $hash = $params[$this->parameter];
79 unset($params[$this->parameter]); 80 unset($params[$this->parameter]);
80 81
81 return $this->computeHash($this->buildUrl($url, $params)) === $hash; 82 return $this->computeHash($this->buildUrl($url, $params)) === $hash;
82 } 83 }
83 84
84 private function computeHash($uri) 85 private function computeHash($uri)
85 { 86 {
86 return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true))); 87 return base64_encode(hash_hmac('sha256', $uri, $this->secret, true));
87 } 88 }
88 89
89 private function buildUrl(array $url, array $params = array()) 90 private function buildUrl(array $url, array $params = [])
90 { 91 {
91 ksort($params, SORT_STRING); 92 ksort($params, SORT_STRING);
92 $url['query'] = http_build_query($params, '', '&'); 93 $url['query'] = http_build_query($params, '', '&');
93 94
94 $scheme = isset($url['scheme']) ? $url['scheme'].'://' : ''; 95 $scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';