def test_add_to_search_query_cache(self):
     query = '{"device_class": "Router"}'
     uid = create_uid(query)
     assert self.db_frontend_editing.add_to_search_query_cache(query) == uid
     assert self.db_frontend_editing.search_query_cache.find_one(
         {'_id': uid})['search_query'] == query
     # check what happens if search is added again
     assert self.db_frontend_editing.add_to_search_query_cache(query) == uid
     assert self.db_frontend_editing.search_query_cache.count_documents(
         {'_id': uid}) == 1
Exemple #2
0
    def uid(self) -> str:
        '''
        Unique identifier of this file.
        Consisting of the file's sha256 hash and it's length in the form `hash_length`.

        :return: uid of this file.
        '''
        if self._uid is None and self.binary is not None:
            self._uid = create_uid(self.binary)
        return self._uid
Exemple #3
0
    def set_binary(self, binary: bytes) -> None:
        '''
        Store the binary representation of the file as byte string.
        Additionally set binary related meta data (size, hash) and compute uid after that.

        :param binary: file in binary representation
        '''
        self.binary = make_bytes(binary)
        self.sha256 = get_sha256(self.binary)
        self.size = len(self.binary)
        self._uid = create_uid(binary)
Exemple #4
0
 def add_to_search_query_cache(self,
                               search_query: str,
                               query_title: Optional[str] = None) -> str:
     query_uid = create_uid(search_query)
     with suppress(DuplicateKeyError):
         self.search_query_cache.insert_one({
             '_id': query_uid,
             'search_query': search_query,
             'query_title': query_title
         })
     return query_uid
def _get_uid_of_analysis_task(analysis_task: dict) -> Optional[str]:
    '''
    Creates a UID (unique identifier) for an analysis task. The UID is generated based on the binary stored in the
    analysis task dict. The return value may be `None` if no binary is contained in the analysis task dict.

    :param analysis_task: The analysis task data.
    :return: A UID based on the binary contained in the analysis task or `None` if there is no binary.
    '''
    if analysis_task['binary']:
        uid = create_uid(analysis_task['binary'])
        return uid
    return None
Exemple #6
0
 def get_uid(self):
     if self.uid is None and self.binary is not None:
         self.uid = create_uid(self.binary)
     return self.uid
Exemple #7
0
 def set_binary(self, binary):
     self.binary = make_bytes(binary)
     self.sha256 = get_sha256(self.binary)
     self.size = len(self.binary)
     self.uid = create_uid(binary)
Exemple #8
0
def get_uid_of_analysis_task(analysis_task):
    if analysis_task['binary']:
        uid = create_uid(analysis_task['binary'])
        return uid
    else:
        return None
Exemple #9
0
 def test_create_uid(self):
     result = create_uid("test")
     self.assertEqual(result, self.test_uid, "uid not correct")
Exemple #10
0
def get_uid_of_analysis_task(analysis_task):
    if analysis_task['binary']:
        # SHA256_SIZE创建文件的唯一uid
        uid = create_uid(analysis_task['binary'])
        return uid
    return None
Exemple #11
0
 def _get_uid(file_path, root_path: Path):
     return create_uid(get_binary_from_file(str(root_path / file_path[1:])))
Exemple #12
0
 def test_create_uid(self):
     result = create_uid('test')
     self.assertEqual(result, self.test_uid, 'uid not correct')