77import os
88import platform
99import shutil
10+ import struct
1011import subprocess
1112from typing import TYPE_CHECKING , BinaryIO
1213
13- from crcmod . predefined import PredefinedCrc
14+ import fastcrc
1415from spacepackets .cfdp .defs import NULL_CHECKSUM_U32 , ChecksumType
1516from spacepackets .cfdp .tlv import FilestoreResponseStatusCode
1617
@@ -351,9 +352,12 @@ def checksum_type_to_crcmod_str(self, checksum_type: ChecksumType) -> str | None
351352 return "crc32c"
352353 raise ChecksumNotImplemented (checksum_type )
353354
355+ """
356+
354357 def _generate_crc_calculator(self, checksum_type: ChecksumType) -> PredefinedCrc:
355358 self._verify_checksum(checksum_type)
356359 return PredefinedCrc(self.checksum_type_to_crcmod_str(checksum_type))
360+ """
357361
358362 def calculate_checksum (
359363 self ,
@@ -370,16 +374,26 @@ def calculate_checksum(
370374 return calc_modular_checksum (file_path )
371375 if segment_len == 0 :
372376 raise ValueError ("segment length can not be 0" )
373- crc_obj = self ._generate_crc_calculator (checksum_type )
377+ func = None
378+ if checksum_type == ChecksumType .CRC_32 :
379+ func = fastcrc .crc32 .iso_hdlc
380+ elif checksum_type == ChecksumType .CRC_32C :
381+ func = fastcrc .crc32 .iscsi
382+ else :
383+ raise ChecksumNotImplemented (checksum_type )
384+ current = func (b"" )
374385 current_offset = 0
375386 # Calculate the file CRC
376387 with open (file_path , "rb" ) as file :
377388 while current_offset < size_to_verify :
378389 read_len = min (segment_len , size_to_verify - current_offset )
379390 if read_len > 0 :
380- crc_obj .update (self .read_from_opened_file (file , current_offset , read_len ))
391+ current = func (
392+ self .read_from_opened_file (file , current_offset , read_len ), current
393+ )
381394 current_offset += read_len
382- return crc_obj .digest ()
395+ assert current is not None
396+ return struct .pack ("!I" , current )
383397
384398
385399HostFilestore = NativeFilestore
0 commit comments