code: def checksum(source: bytes) -> int:
      
      if len(source) % 2:  # if the total length is odd, padding with one octet of zeros for computing the checksum
          source += b'\x00'
      sum = 0
      for i in range(0, len(source), 2):
          sum = ones_comp_sum16(sum, (source[i + 1] << 8) + source[i])
      return ~sum & 0xffff
docs: Calculates the checksum of the input bytes.
  
      RFC1071: https://tools.ietf.org/html/rfc1071
      RFC792: https://tools.ietf.org/html/rfc792
  
      Args:
          source: The input to be calculated.
  
      Returns:
          Calculated checksum.