(sample: string | Uint8Array)
| 174 | } |
| 175 | |
| 176 | private async forRequest(sample: string | Uint8Array): Promise<VaasVerdict> { |
| 177 | const ws = this.getAuthenticatedWebSocket(); |
| 178 | return new Promise((resolve, reject) => { |
| 179 | const guid = uuidv4(); |
| 180 | if (this.debug) console.debug("uuid", guid); |
| 181 | this.verdictPromises.set(guid, { |
| 182 | resolve: async (verdictResponse: VerdictResponse) => { |
| 183 | if ( |
| 184 | verdictResponse.verdict === Verdict.UNKNOWN && |
| 185 | typeof sample !== "string" |
| 186 | ) { |
| 187 | await this.upload(verdictResponse, sample, sample.length); |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | this.verdictPromises.delete(guid); |
| 192 | resolve( |
| 193 | new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detection, verdictResponse.file_type, verdictResponse.mime_type), |
| 194 | ); |
| 195 | }, |
| 196 | reject: (reason) => reject(reason), |
| 197 | }); |
| 198 | |
| 199 | let hash = |
| 200 | typeof sample === "string" |
| 201 | ? sample |
| 202 | : Vaas.toHexString(sha256.hash(sample)); |
| 203 | const verdictReq = JSON.stringify( |
| 204 | defaultSerializer.serialize( |
| 205 | new VerdictRequest(hash, guid, this.connection!.sessionId as string), |
| 206 | ), |
| 207 | ); |
| 208 | ws.send(verdictReq); |
| 209 | }); |
| 210 | } |
| 211 | |
| 212 | private async forUrlRequest(url: URL): Promise<VaasVerdict> { |
| 213 | const ws = this.getAuthenticatedWebSocket(); |
no test coverage detected