Skip to content

Commit

Permalink
refactor: rename module to packaging
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <[email protected]>
  • Loading branch information
dbluhm committed Nov 2, 2023
1 parent 3c7bf0e commit 1e754e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 15 additions & 15 deletions didcomm_messaging/didcomm.py → didcomm_messaging/packaging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Class DIDComm Messaging interface."""
"""PackagingService interface."""


from dataclasses import dataclass
Expand All @@ -20,7 +20,7 @@ class PackedMessageMetadata(Generic[S]):
sender_kid: Optional[str]


class DIDCommMessagingError(Exception):
class PackagingServiceError(Exception):
"""Represents an error from the DIDComm Messaging interface."""


Expand All @@ -45,15 +45,15 @@ async def extract_packed_message_metadata( # noqa: C901
try:
wrapper = JweEnvelope.from_json(enc_message)
except ValueError:
raise DIDCommMessagingError("Invalid packed message")
raise PackagingServiceError("Invalid packed message")

alg = wrapper.protected.get("alg")
if not alg:
raise DIDCommMessagingError("Missing alg header")
raise PackagingServiceError("Missing alg header")

method = next((m for m in ("ECDH-1PU", "ECDH-ES") if m in alg), None)
if not method:
raise DIDCommMessagingError(
raise PackagingServiceError(
f"Unsupported DIDComm encryption algorithm: {alg}"
)

Expand All @@ -65,7 +65,7 @@ async def extract_packed_message_metadata( # noqa: C901
break

if not recip_key:
raise DIDCommMessagingError("No recognized recipient key")
raise PackagingServiceError("No recognized recipient key")

if method == "ECDH-1PU":
sender_kid_apu = None
Expand All @@ -74,12 +74,12 @@ async def extract_packed_message_metadata( # noqa: C901
try:
sender_kid_apu = from_b64url(apu).decode("utf-8")
except (UnicodeDecodeError, ValueError):
raise DIDCommMessagingError("Invalid apu value")
raise PackagingServiceError("Invalid apu value")
sender_kid = wrapper.protected.get("skid") or sender_kid_apu
if sender_kid_apu and sender_kid != sender_kid_apu:
raise DIDCommMessagingError("Mismatch between skid and apu")
raise PackagingServiceError("Mismatch between skid and apu")
if not sender_kid:
raise DIDCommMessagingError("Sender key ID not provided")
raise PackagingServiceError("Sender key ID not provided")
# FIXME - validate apv if present?

return PackedMessageMetadata(wrapper, method, recip_key, sender_kid)
Expand All @@ -92,7 +92,7 @@ async def unpack(self, enc_message: Union[str, bytes]) -> bytes:
return await self.crypto.ecdh_es_decrypt(enc_message, metadata.recip_key)

if not metadata.sender_kid:
raise DIDCommMessagingError("Missing sender key ID")
raise PackagingServiceError("Missing sender key ID")

sender_vm = await self.resolver.resolve_and_dereference_verification_method(
metadata.sender_kid
Expand All @@ -112,15 +112,15 @@ async def recip_for_kid_or_default_for_did(self, kid_or_did: str) -> P:
else:
doc = await self.resolver.resolve_and_parse(kid_or_did)
if not doc.key_agreement:
raise DIDCommMessagingError(
raise PackagingServiceError(
"No key agreement methods found; cannot determine recipient"
)

default = doc.key_agreement[0]
if isinstance(default, DIDUrl):
vm = doc.dereference(default)
if not isinstance(vm, VerificationMethod):
raise DIDCommMessagingError(
raise PackagingServiceError(
f"Expected verification method, found: {type(vm)}"
)
else:
Expand All @@ -135,15 +135,15 @@ async def default_sender_kid_for_did(self, did: str) -> str:

doc = await self.resolver.resolve_and_parse(did)
if not doc.key_agreement:
raise DIDCommMessagingError(
raise PackagingServiceError(
"No key agreement methods found; cannot determine recipient"
)

default = doc.key_agreement[0]
if isinstance(default, DIDUrl):
vm = doc.dereference(default)
if not isinstance(vm, VerificationMethod):
raise DIDCommMessagingError(
raise PackagingServiceError(
f"Expected verification method, found: {type(vm)}"
)
else:
Expand All @@ -167,7 +167,7 @@ async def pack(
await self.secrets.get_secret_by_kid(sender_kid) if sender_kid else None
)
if frm and not sender_key:
raise DIDCommMessagingError("No sender key found")
raise PackagingServiceError("No sender key found")

if sender_key:
return await self.crypto.ecdh_1pu_encrypt(recip_keys, sender_key, message)
Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from aries_askar import Key, KeyAlg
from didcomm_messaging.crypto.askar import AskarCryptoService, AskarSecretKey
from didcomm_messaging.crypto.basic import InMemorySecretsManager
from didcomm_messaging.didcomm import PackagingService
from didcomm_messaging.packaging import PackagingService
from didcomm_messaging.multiformats import multibase
from didcomm_messaging.multiformats import multicodec
from didcomm_messaging.resolver.peer import Peer2, Peer4
Expand Down

0 comments on commit 1e754e4

Please sign in to comment.