Skip to content

Commit 4b23c54

Browse files
committed
fix(model): Do a simplified process of hash algorithm
Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
1 parent d70c2e7 commit 4b23c54

5 files changed

Lines changed: 26 additions & 124 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "uv_build"
44

55
[project]
66
name = "python-ort"
7-
version = "0.8.6"
7+
version = "0.8.7"
88
description = "A Python Ort model serialization library"
99
readme = "README.md"
1010
license = "MIT"

src/ort/models/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .dependency_graph_node import DependencyGraphNode
1919
from .dependency_reference import DependencyReference
2020
from .hash import Hash
21-
from .hash_algorithm import HashAlgorithm
2221
from .identifier import Identifier
2322
from .issue import Issue
2423
from .ort_result import OrtResult
@@ -48,7 +47,6 @@
4847
"DependencyGraphNode",
4948
"DependencyReference",
5049
"Hash",
51-
"HashAlgorithm",
5250
"Identifier",
5351
"Includes",
5452
"Excludes",

src/ort/models/hash.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# SPDX-FileCopyrightText: 2025 Helio Chissini de Castro <heliocastro@gmail.com>
22
# SPDX-License-Identifier: MIT
33

4-
from pydantic import BaseModel, Field
4+
from pydantic import BaseModel, Field, field_validator
55

6-
from .hash_algorithm import HashAlgorithm
6+
ALGO_LIST: dict[str, list] = {
7+
"MD5": ["MD5"],
8+
"SHA1": ["SHA-1", "SHA1"],
9+
"SHA256": ["SHA-256", "SHA256"],
10+
"SHA384": ["SHA-384", "SHA384"],
11+
"SHA512": ["SHA-512", "SHA512"],
12+
"SHA1GIT": ["SHA-1-GIT", "SHA1-GIT", "SHA1GIT", "SWHID"],
13+
}
714

815

916
class Hash(BaseModel):
@@ -15,5 +22,18 @@ class Hash(BaseModel):
1522
algorithm (HashAlgorithm): The algorithm used to calculate the hash value.
1623
"""
1724

18-
value: str = Field(description="The value calculated using the hash algorithm.")
19-
algorithm: HashAlgorithm = Field(description="The algorithm used to calculate the hash value.")
25+
value: str = Field(
26+
description="The value calculated using the hash algorithm.",
27+
)
28+
algorithm: str = Field(
29+
default="NONE",
30+
description="The algorithm used to calculate the hash value.",
31+
)
32+
33+
@field_validator("algorithm", mode="before")
34+
@classmethod
35+
def validate_algorithm(cls, value):
36+
for key, item in ALGO_LIST.items():
37+
if value in item:
38+
return key
39+
return "UNKNOWN"

src/ort/models/hash_algorithm.py

Lines changed: 0 additions & 116 deletions
This file was deleted.

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)