Skip to content

Commit

Permalink
transparency: reorder models
Browse files Browse the repository at this point in the history
Apparently Pydantic needs this now.

Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw committed Jul 13, 2023
1 parent 57a5348 commit 5cae7be
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions sigstore/transparency.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,43 @@
from sigstore._utils import B64Str


class LogInclusionProof(BaseModel):
"""
Represents an inclusion proof for a transparency log entry.
"""

model_config = ConfigDict(populate_by_name=True)

checkpoint: StrictStr = Field(..., alias="checkpoint")
hashes: List[StrictStr] = Field(..., alias="hashes")
log_index: StrictInt = Field(..., alias="logIndex")
root_hash: StrictStr = Field(..., alias="rootHash")
tree_size: StrictInt = Field(..., alias="treeSize")

@validator("log_index")
def _log_index_positive(cls, v: int) -> int:
if v < 0:
raise ValueError(f"Inclusion proof has invalid log index: {v} < 0")
return v

@validator("tree_size")
def _tree_size_positive(cls, v: int) -> int:
if v < 0:
raise ValueError(f"Inclusion proof has invalid tree size: {v} < 0")
return v

@validator("tree_size")
def _log_index_within_tree_size(
cls, v: int, values: Dict[str, Any], **kwargs: Any
) -> int:
if "log_index" in values and v <= values["log_index"]:
raise ValueError(
"Inclusion proof has log index greater than or equal to tree size: "
f"{v} <= {values['log_index']}"
)
return v


@dataclass(frozen=True)
class LogEntry:
"""
Expand Down Expand Up @@ -136,40 +173,3 @@ def encode_canonical(self) -> bytes:
}

return encode_canonical(payload).encode() # type: ignore


class LogInclusionProof(BaseModel):
"""
Represents an inclusion proof for a transparency log entry.
"""

model_config = ConfigDict(populate_by_name=True)

checkpoint: StrictStr = Field(..., alias="checkpoint")
hashes: List[StrictStr] = Field(..., alias="hashes")
log_index: StrictInt = Field(..., alias="logIndex")
root_hash: StrictStr = Field(..., alias="rootHash")
tree_size: StrictInt = Field(..., alias="treeSize")

@validator("log_index")
def _log_index_positive(cls, v: int) -> int:
if v < 0:
raise ValueError(f"Inclusion proof has invalid log index: {v} < 0")
return v

@validator("tree_size")
def _tree_size_positive(cls, v: int) -> int:
if v < 0:
raise ValueError(f"Inclusion proof has invalid tree size: {v} < 0")
return v

@validator("tree_size")
def _log_index_within_tree_size(
cls, v: int, values: Dict[str, Any], **kwargs: Any
) -> int:
if "log_index" in values and v <= values["log_index"]:
raise ValueError(
"Inclusion proof has log index greater than or equal to tree size: "
f"{v} <= {values['log_index']}"
)
return v

0 comments on commit 5cae7be

Please sign in to comment.