1 | <?php |
||
6 | final class Auth |
||
7 | { |
||
8 | public $accessKey; |
||
9 | public $secretKey; |
||
10 | |||
11 | public function __construct($accessKey, $secretKey) |
||
16 | |||
17 | 6 | public function getAccessKey() |
|
18 | { |
||
19 | 6 | return $this->accessKey; |
|
20 | } |
||
21 | |||
22 | 87 | public function sign($data) |
|
23 | { |
||
24 | 87 | $hmac = hash_hmac('sha1', $data, $this->secretKey, true); |
|
25 | 87 | $aa = $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac); |
|
|
|||
26 | 87 | return $this->accessKey . ':' . \Qiniu\base64_urlSafeEncode($hmac); |
|
27 | } |
||
28 | |||
29 | 24 | public function signWithData($data) |
|
30 | { |
||
31 | 24 | $encodedData = \Qiniu\base64_urlSafeEncode($data); |
|
32 | 24 | return $this->sign($encodedData) . ':' . $encodedData; |
|
33 | } |
||
34 | |||
35 | 48 | public function signRequest($urlString, $body, $contentType = null) |
|
36 | { |
||
37 | 48 | $url = parse_url($urlString); |
|
38 | 48 | $data = ''; |
|
39 | 48 | if (array_key_exists('path', $url)) { |
|
40 | 45 | $data = $url['path']; |
|
41 | 45 | } |
|
42 | 48 | if (array_key_exists('query', $url)) { |
|
43 | 9 | $data .= '?' . $url['query']; |
|
44 | 9 | } |
|
45 | 48 | $data .= "\n"; |
|
46 | |||
47 | 48 | if ($body !== null && $contentType === 'application/x-www-form-urlencoded') { |
|
48 | 24 | $data .= $body; |
|
49 | 24 | } |
|
50 | 48 | return $this->sign($data); |
|
51 | } |
||
52 | |||
53 | public function verifyCallback($contentType, $originAuthorization, $url, $body) |
||
58 | |||
59 | 12 | public function privateDownloadUrl($baseUrl, $expires = 3600) |
|
74 | |||
75 | 21 | public function uploadToken($bucket, $key = null, $expires = 3600, $policy = null, $strictPolicy = true) |
|
76 | { |
||
77 | 21 | $deadline = time() + $expires; |
|
78 | 21 | $scope = $bucket; |
|
90 | |||
91 | /** |
||
92 | *上传策略,参数规格详见 |
||
93 | *http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html |
||
94 | */ |
||
95 | private static $policyFields = array( |
||
96 | 'callbackUrl', |
||
97 | 'callbackBody', |
||
98 | 'callbackHost', |
||
99 | 'callbackBodyType', |
||
100 | 'callbackFetchKey', |
||
101 | |||
102 | 'returnUrl', |
||
103 | 'returnBody', |
||
104 | |||
105 | 'endUser', |
||
106 | 'saveKey', |
||
107 | 'insertOnly', |
||
108 | |||
109 | 'detectMime', |
||
110 | 'mimeLimit', |
||
111 | 'fsizeMin', |
||
112 | 'fsizeLimit', |
||
113 | |||
114 | 'persistentOps', |
||
115 | 'persistentNotifyUrl', |
||
116 | 'persistentPipeline', |
||
117 | |||
118 | 'deleteAfterDays', |
||
119 | 'fileType', |
||
120 | 'isPrefixalScope', |
||
121 | ); |
||
122 | |||
123 | 21 | private static function copyPolicy(&$policy, $originPolicy, $strictPolicy) |
|
135 | |||
136 | 45 | public function authorization($url, $body = null, $contentType = null) |
|
141 | |||
142 | public function authorizationV2($url, $method, $body = null, $contentType = null) |
||
188 | |||
189 | public function RtcToken($method, $url, $contentType, $body) |
||
215 | } |
||
216 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.