Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/scalars.py
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
@content_hash_scalar.value_parser | @content_hash_scalar.value_parser | ||||
def validate_content_hash(value): | def validate_content_hash(value): | ||||
try: | try: | ||||
hash_type, hash_string = value.split(":") | hash_type, hash_string = value.split(":") | ||||
hash_value = hashutil.hash_to_bytes(hash_string) | hash_value = hashutil.hash_to_bytes(hash_string) | ||||
except ValueError as e: | except ValueError as e: | ||||
raise InvalidInputError("Invalid content checksum", e) | raise InvalidInputError("Invalid content hash", e) | ||||
if hash_type not in hashutil.ALGORITHMS: | if hash_type not in hashutil.ALGORITHMS: | ||||
raise InvalidInputError("Invalid hash algorithm") | raise InvalidInputError("Invalid hash algorithm") | ||||
return hash_type, hash_value | return hash_type, hash_value |