跳转到主要内容

一个库,用于在Sigstore Bundles和PEP-740认证对象之间进行转换

项目描述

PyPI认证模型

CI PyPI version Packaging status

一个库,用于在Sigstore Bundles和PEP 740认证对象之间进行转换

安装

python -m pip install pypi-attestation-models

使用

请参阅完整的API文档此处

签名和验证

使用这些API通过签名Python工件(例如:sdist或wheel文件)来创建PEP 740兼容的Attestation对象,并验证Attestation对象与Python工件。

from pathlib import Path

from pypi_attestation_models import Attestation, AttestationPayload
from sigstore.oidc import Issuer
from sigstore.sign import SigningContext
from sigstore.verify import Verifier, policy

artifact_path = Path("test_package-0.0.1-py3-none-any.whl")

# Sign a Python artifact
issuer = Issuer.production()
identity_token = issuer.identity_token()
signing_ctx = SigningContext.production()
with signing_ctx.signer(identity_token, cache=True) as signer:
    attestation = AttestationPayload.from_dist(artifact_path).sign(signer)

print(attestation.model_dump_json())

# Verify an attestation against a Python artifact
attestation_path = Path("test_package-0.0.1-py3-none-any.whl.attestation")
attestation = Attestation.model_validate_json(attestation_path.read_bytes())
verifier = Verifier.production()
policy = policy.Identity(identity="example@gmail.com", issuer="https://#")
attestation.verify(verifier, policy, attestation_path)

低级别模型转换

这些转换假定作为输入使用的任何Sigstore Bundle都是通过签名AttestationPayload对象创建的。

from pathlib import Path
from pypi_attestation_models import pypi_to_sigstore, sigstore_to_pypi, Attestation
from sigstore.models import Bundle

# Sigstore Bundle -> PEP 740 Attestation object
bundle_path = Path("test_package-0.0.1-py3-none-any.whl.sigstore")
with bundle_path.open("rb") as f:
    sigstore_bundle = Bundle.from_json(f.read())
attestation_object = sigstore_to_pypi(sigstore_bundle)
print(attestation_object.model_dump_json())


# PEP 740 Attestation object -> Sigstore Bundle
attestation_path = Path("attestation.json")
with attestation_path.open("rb") as f:
    attestation = Attestation.model_validate_json(f.read())
bundle = pypi_to_sigstore(attestation)
print(bundle.to_json())

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

pypi_attestation_models-0.0.5.tar.gz (9.7 kB 查看散列值)

上传时间

构建分发版本

pypi_attestation_models-0.0.5-py3-none-any.whl (10.0 kB 查看散列值)

上传时间 Python 3