MCPcopy Create free account
hub / github.com/ICE27182/Python-3D-renderer / check_crc

Method check_crc

png.py:110–117  ·  view source on GitHub ↗

Check if the data matches the crc part. Raise Exception if not.

(image_bytes:bytes, chunk_starting_index:int)

Source from the content-addressed store, hash-verified

108
109
110 def check_crc(image_bytes:bytes, chunk_starting_index:int) -> None:
111 """Check if the data matches the crc part. Raise Exception if not."""
112 chunk_length = Png.get_chunk_length(image_bytes, chunk_starting_index)
113 # Check if the crc value calculated according to the chunk
114 if (crc32(image_bytes[chunk_starting_index+4:chunk_starting_index+8+chunk_length]) !=
115 int.from_bytes(image_bytes[chunk_starting_index+chunk_length+8:chunk_starting_index+chunk_length+12], byteorder="big")
116 ):
117 raise Exception("CRC Failed")
118
119
120 def get_chunk_length(image_bytes:bytes, chunk_starting_index:int) -> int:

Callers 3

get_image_propertiesMethod · 0.80
get_paletteMethod · 0.80
get_all_idat_dataMethod · 0.80

Calls 1

get_chunk_lengthMethod · 0.80

Tested by

no test coverage detected