* Get the verdict for a file by its SHA256 hash * @param Sha256 $sha256 The SHA256 hash of the file to check * @param ForSha256Options|null $options Options for the request * @param Cancellation|null $cancellation Cancellation token * @return Future A future that resolves to a VaasVerdict * @throws HttpException If the request fails * @throws VaasClientException The r
(Sha256 $sha256, ?ForSha256Options $options = null, ?Cancellation $cancellation = null)
| 81 | * @throws VaasServerException The server encountered an internal error. Recommended actions: You may retry the request after a certain delay. If the problem persists contact G DATA. |
| 82 | */ |
| 83 | public function forSha256Async(Sha256 $sha256, ?ForSha256Options $options = null, ?Cancellation $cancellation = null): Future |
| 84 | { |
| 85 | return async(function () use ($sha256, $options, $cancellation) { |
| 86 | $this->logger->debug("Requesting verdict for SHA256: $sha256"); |
| 87 | |
| 88 | $options = $options ?? ForSha256Options::fromVaasOptions($this->options); |
| 89 | |
| 90 | $url = sprintf('%s/files/%s/report/?useCache=%s&useHashLookup=%s', |
| 91 | $this->options->vaasUrl, |
| 92 | $sha256, |
| 93 | json_encode($options->useCache), |
| 94 | json_encode($options->useHashLookup |
| 95 | )); |
| 96 | |
| 97 | while (true) { |
| 98 | $request = new Request($url, 'GET'); |
| 99 | $this->enrichRequestAsync($request,$this->options->timeout, $options->vaasRequestId)->await($cancellation); |
| 100 | $this->logger->debug("Send request for SHA256: " . self::logUri($request)); |
| 101 | $response = $this->httpClient->request($request, $cancellation); |
| 102 | |
| 103 | switch ($response->getStatus()) { |
| 104 | case 200: |
| 105 | $report = json_decode($response->getBody()->buffer($cancellation), true); |
| 106 | $verdict = VaasVerdict::from($report); |
| 107 | $this->logger->info("Received verdict for $sha256: $verdict"); |
| 108 | return $verdict; |
| 109 | case 202: |
| 110 | $this->logger->debug("Verdict for $sha256 is not ready yet, retrying..."); |
| 111 | break; |
| 112 | case 400: |
| 113 | $this->logger->error("Bad request for SHA256: $sha256"); |
| 114 | throw new VaasClientException("Bad request. The format of the SHA256 is wrong."); |
| 115 | case 401: |
| 116 | $this->logger->error("Unauthorized request for SHA256: $sha256"); |
| 117 | throw new VaasAuthenticationException("Unauthorized. Check your credentials."); |
| 118 | case 403: |
| 119 | $this->logger->error("Forbidden request for SHA256: $sha256"); |
| 120 | throw new VaasClientException("Forbidden. You are not allowed to use this endpoint."); |
| 121 | default: |
| 122 | $this->logger->error("Error requesting verdict for SHA256: $sha256"); |
| 123 | throw $this->parseVaasError($response); |
| 124 | } |
| 125 | } |
| 126 | }, $cancellation); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Get the verdict for a File |
no test coverage detected