Skip to content

Commit f34c057

Browse files
authored
Change: refactor to do code more reusable (#808)
1 parent fb64450 commit f34c057

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ospd_openvas/vthelper.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ def get_vt_iterator(
209209
if vt:
210210
yield (vt_id, vt)
211211

212-
def calculate_vts_collection_hash(self) -> str:
213-
"""Calculate the vts collection sha256 hash."""
214-
m = sha256() # pylint: disable=invalid-name
215-
212+
def vt_verification_string_iter(self) -> str:
216213
# for a reproducible hash calculation
217214
# the vts must already be sorted in the dictionary.
218215
for vt_id, vt in self.get_vt_iterator(details=False):
@@ -226,12 +223,17 @@ def calculate_vts_collection_hash(self) -> str:
226223
+ param.get('name')
227224
+ param.get('default')
228225
)
229-
230-
m.update(
226+
yield (
231227
(vt_id + vt.get('modification_time')).encode('utf-8')
232228
+ param_chain.encode('utf-8')
233229
)
234230

231+
def calculate_vts_collection_hash(self) -> str:
232+
"""Calculate the vts collection sha256 hash."""
233+
m = sha256() # pylint: disable=invalid-name
234+
235+
for chunk in self.vt_verification_string_iter():
236+
m.update(chunk)
235237
return m.hexdigest()
236238

237239
def get_severity_score(self, vt_aux: dict) -> Optional[float]:

0 commit comments

Comments
 (0)