#!/usr/bin/env python3 # # Copyright (C) 2023 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.
"""
Define data classes that model SBOMs defined by SPDX. The data classes could be
written out to different formats (tagvalue, JSON, etc) of SPDX with corresponding
writer utilities.
def add_external_ref(self, external_ref): ifnot any(external_ref.uri == ref.uri for ref in self.external_refs):
self.external_refs.append(external_ref)
def add_package(self, package):
p = next((p for p in self.packages if package.id == p.id), None) ifnot p:
self.packages.append(package) else: for license_id in package.declared_license_ids: if license_id notin p.declared_license_ids:
p.declared_license_ids.append(license_id)
def add_relationship(self, rel): ifnot any(rel.id1 == r.id1 and rel.id2 == r.id2 and rel.relationship == r.relationship for r in self.relationships):
self.relationships.append(rel)
def add_license(self, license): ifnot any(license.id == l.id for l in self.licenses):
self.licenses.append(license)
def generate_packages_verification_code(self): for package in self.packages: ifnot package.file_ids: continue
checksums = [] for file in self.files: if file.id in package.file_ids:
checksums.append(file.checksum.split(': ')[1])
checksums.sort()
h = hashlib.sha1()
h.update(''.join(checksums).encode(encoding='utf-8'))
package.verification_code = h.hexdigest()
def encode_for_spdxid(s): """Simple encode for string values used in SPDXID which uses the charset of A-Za-Z0-9.-"""
result = '' for c in s: if c.isalnum() or c in'.-':
result += c elif c in'_@/':
result += '-' else:
result += '0x' + c.encode('utf-8').hex()
return result.lstrip('-')
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-28)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.