Skip to content

Commit 79a57b0

Browse files
committed
feat: Attestation.statement
Signed-off-by: William Woodruff <william@trailofbits.com>
1 parent 478c93f commit 79a57b0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- `Attestation.statement` has been added as a convenience API for accessing
13+
the attestation's enveloped statement as a dictionary
14+
1015
## [0.0.15]
1116

1217
This is a corrective release for [0.0.14].

src/pypi_attestations/_impl.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import annotations
77

88
import base64
9+
import json
910
from enum import Enum
1011
from typing import TYPE_CHECKING, Annotated, Any, Literal, NewType, Optional, Union, get_args
1112

@@ -148,6 +149,15 @@ class Attestation(BaseModel):
148149
The enveloped attestation statement and signature.
149150
"""
150151

152+
@property
153+
def statement(self) -> dict[str, Any]:
154+
"""Return the statement within this attestation's envelope.
155+
156+
The value returned here is a dictionary, in the shape of an
157+
in-toto statement.
158+
"""
159+
return json.loads(self.envelope.statement)
160+
151161
@classmethod
152162
def sign(cls, signer: Signer, dist: Distribution) -> Attestation:
153163
"""Create an envelope, with signature, from the given Python distribution.

test/test_impl.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,13 @@ def test_verify(self) -> None:
168168
attestation = impl.Attestation.model_validate_json(dist_attestation_path.read_text())
169169
predicate_type, predicate = attestation.verify(pol, dist, staging=True)
170170

171-
assert predicate_type == "https://docs.pypi.org/attestations/publish/v1"
172-
assert predicate is None
171+
assert attestation.statement["_type"] == "https://in-toto.io/Statement/v1"
172+
assert (
173+
predicate_type
174+
== attestation.statement["predicateType"]
175+
== "https://docs.pypi.org/attestations/publish/v1"
176+
)
177+
assert predicate is None and attestation.statement["predicate"] is None
173178

174179
# convert the attestation to a bundle and verify it that way too
175180
bundle = attestation.to_bundle()

0 commit comments

Comments
 (0)