Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/tests] Unit tests #2

Merged
merged 21 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: added support for EC2Key
PascalDR committed Jan 31, 2024
commit 69352989ca186ea06d51a25982e62e032016996f
16 changes: 11 additions & 5 deletions pymdoccbor/mdoc/issuer.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
import cbor2
import logging

from pycose.keys import CoseKey
from pycose.keys import CoseKey, EC2Key
from typing import Union

from pymdoccbor.mso.issuer import MsoIssuer
@@ -16,7 +16,7 @@ class MdocCborIssuer:
MdocCborIssuer helper class to create a new mdoc
"""

def __init__(self, private_key: Union[dict, CoseKey]):
def __init__(self, private_key: Union[dict, EC2Key, CoseKey]):
"""
Create a new MdocCborIssuer instance
@@ -28,11 +28,17 @@ def __init__(self, private_key: Union[dict, CoseKey]):
self.version: str = '1.0'
self.status: int = 0

if not private_key:
if isinstance(private_key, dict):
self.private_key = CoseKey.from_dict(private_key)
elif isinstance(private_key, EC2Key):
ec2_encoded = private_key.encode()
ec2_decoded = CoseKey.decode(ec2_encoded)
self.private_key = ec2_decoded
elif isinstance(private_key, CoseKey):
self.private_key = private_key
else:
raise MissingPrivateKey("You must provide a private key")

if private_key and isinstance(private_key, dict):
self.private_key = CoseKey.from_dict(private_key)

self.signed :dict = {}

6 changes: 5 additions & 1 deletion pymdoccbor/mso/issuer.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ class MsoIssuer(MsoX509Fabric):
def __init__(
self,
data: dict,
private_key: Union[dict, CoseKey],
private_key: Union[dict, EC2Key, CoseKey],
digest_alg: str = settings.PYMDOC_HASHALG
):
"""
@@ -48,6 +48,10 @@ def __init__(
self.private_key.kid = str(uuid.uuid4())
elif private_key and isinstance(private_key, CoseKey):
self.private_key = private_key
elif private_key and isinstance(private_key, EC2Key):
ec2_encoded = private_key.encode()
ec2_decoded = CoseKey.decode(ec2_encoded)
self.private_key = ec2_decoded
else:
raise MsoPrivateKeyRequired(
"MSO Writer requires a valid private key"