Check if the data matches the crc part. Raise Exception if not.
(image_bytes:bytes, chunk_starting_index:int)
| 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: |
no test coverage detected