Skip to content

Commit fa52b43

Browse files
committed
feat: add DER encoding methods and update key type alias in key_utils
Signed-off-by: MonaaEid <monaa_eid@hotmail.com>
1 parent 7d0c67c commit fa52b43

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/hiero_sdk_python/crypto/public_key.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,15 @@ def _encode_der_oid(cls, oid: str) -> bytes:
475475
if len(parts) < 2:
476476
raise ValueError("OID must contain at least two components")
477477

478+
is_valid = (
479+
len(parts) >= 2 and
480+
parts[0] in (0, 1, 2) and
481+
parts[1] >= 0 and
482+
(parts[0] == 2 or parts[1] < 40)
483+
)
484+
if not is_valid:
485+
raise ValueError(f"Invalid OID structure for '{oid}'")
486+
478487
first, second = parts[0], parts[1]
479488
if first not in (0, 1, 2):
480489
raise ValueError("Invalid OID first component")

tests/unit/keys_public_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ def test_encode_der_oid_invalid_components_raise():
260260
with pytest.raises(ValueError, match="at least two"):
261261
PublicKey._encode_der_oid("1")
262262

263-
with pytest.raises(ValueError, match="first component"):
263+
with pytest.raises(ValueError, match="Invalid OID structure for '3.1.1'"):
264264
PublicKey._encode_der_oid("3.1.1")
265265

266-
with pytest.raises(ValueError, match="second component"):
266+
with pytest.raises(ValueError, match="Invalid OID structure for '1.40.1'"):
267267
PublicKey._encode_der_oid("1.40.1")
268268

269269
with pytest.raises(ValueError, match="non-negative"):

0 commit comments

Comments
 (0)