spdx_tools.spdx.validation.package_verification_code_validator
1# SPDX-FileCopyrightText: 2022 spdx contributors 2# 3# SPDX-License-Identifier: Apache-2.0 4 5import re 6 7from beartype.typing import List 8 9from spdx_tools.spdx.model import PackageVerificationCode 10from spdx_tools.spdx.validation.validation_message import SpdxElementType, ValidationContext, ValidationMessage 11 12 13def validate_verification_code(verification_code: PackageVerificationCode, parent_id: str) -> List[ValidationMessage]: 14 validation_messages: List[ValidationMessage] = [] 15 context = ValidationContext( 16 parent_id=parent_id, element_type=SpdxElementType.PACKAGE_VERIFICATION_CODE, full_element=verification_code 17 ) 18 19 for file in verification_code.excluded_files: 20 if file.startswith("/"): 21 validation_messages.append( 22 ValidationMessage(f'file name must not be an absolute path starting with "/", but is: {file}', context) 23 ) 24 25 value: str = verification_code.value 26 if not re.match("^[0-9a-f]{40}$", value): 27 validation_messages.append( 28 ValidationMessage( 29 f"value of verification_code must consist of 40 lowercase hexadecimal digits, but is: {value} " 30 f"(length: {len(value)} digits)", 31 context, 32 ) 33 ) 34 35 return validation_messages
def
validate_verification_code( verification_code: spdx_tools.spdx.model.package.PackageVerificationCode, parent_id: str) -> list[spdx_tools.spdx.validation.validation_message.ValidationMessage]:
14def validate_verification_code(verification_code: PackageVerificationCode, parent_id: str) -> List[ValidationMessage]: 15 validation_messages: List[ValidationMessage] = [] 16 context = ValidationContext( 17 parent_id=parent_id, element_type=SpdxElementType.PACKAGE_VERIFICATION_CODE, full_element=verification_code 18 ) 19 20 for file in verification_code.excluded_files: 21 if file.startswith("/"): 22 validation_messages.append( 23 ValidationMessage(f'file name must not be an absolute path starting with "/", but is: {file}', context) 24 ) 25 26 value: str = verification_code.value 27 if not re.match("^[0-9a-f]{40}$", value): 28 validation_messages.append( 29 ValidationMessage( 30 f"value of verification_code must consist of 40 lowercase hexadecimal digits, but is: {value} " 31 f"(length: {len(value)} digits)", 32 context, 33 ) 34 ) 35 36 return validation_messages