def test_compute_hashes(self): """Test hash functions for basic file.""" sha, md5 = file_hash.compute_hashes('/hello_world') self.assertEqual( hashlib.sha256(self._test_contents.encode('utf-8')).hexdigest(), sha) self.assertEqual( hashlib.md5(self._test_contents.encode('utf-8')).hexdigest(), md5)
def __enter__(self): """Download the binary from S3 and run YARA analysis.""" self._download_from_s3() self.computed_sha, self.computed_md5 = file_hash.compute_hashes(self.download_path) LOGGER.debug('Running YARA analysis') self.yara_matches = self.yara_analyzer.analyze( self.download_path, original_target_path=self.observed_path) return self
def __enter__(self) -> Any: # mypy/typing doesn't support recursive type yet """Download the binary from S3 and run YARA analysis.""" self._download_from_s3() self.computed_sha, self.computed_md5 = file_hash.compute_hashes(self.download_path) LOGGER.debug('Running YARA analysis') self.yara_matches = self.yara_analyzer.analyze( self.download_path, original_target_path=self.filepath ) return self
def test_compute_hashes_empty_file(self): """Test hash functions for an empty file.""" sha, md5 = file_hash.compute_hashes('/empty_file') self.assertEqual(hashlib.sha256().hexdigest(), sha) self.assertEqual(hashlib.md5().hexdigest(), md5)