Algorithm-routing crypto provider for Swarmauri
Project description
Swarmauri Crypto Composite
CompositeCrypto is an algorithm-routing crypto provider that delegates encryption
operations to the first child provider that advertises support for the requested
algorithm. Its behaviour is defined entirely by the wrapped providers:
- Aggregates each provider's
supports()capabilities and removes duplicates. - Normalises requested algorithms before routing so stylistic variants still match.
- Requires at least one child provider to be supplied at construction time.
- Exposes the full asynchronous
ICryptosurface area (encrypt, wrap, seal, etc.).
Installation
Choose the tool that best fits your workflow:
pip install swarmauri_crypto_composite
poetry add swarmauri_crypto_composite
uv add swarmauri_crypto_composite
Usage
"""Route crypto operations to the provider that supports the requested algorithm."""
import asyncio
from swarmauri_crypto_composite import CompositeCrypto
from swarmauri_core.crypto.ICrypto import ICrypto
from swarmauri_core.crypto.types import (
AEADCiphertext,
ExportPolicy,
KeyRef,
KeyType,
KeyUse,
)
class DummyCrypto(ICrypto):
def __init__(self, name: str, alg: str) -> None:
self._name = name
self._alg = alg
def supports(self):
return {"encrypt": (self._alg,)}
async def encrypt(self, key, pt, *, alg=None, aad=None, nonce=None):
return AEADCiphertext(
kid="dummy",
version=1,
alg=alg or self._alg,
nonce=b"",
ct=self._name.encode(),
tag=b"",
)
async def decrypt(self, key, ct, *, aad=None): # pragma: no cover - demo only
raise NotImplementedError
async def wrap(self, kek, *, dek=None, wrap_alg=None, nonce=None): # pragma: no cover - demo only
raise NotImplementedError
async def unwrap(self, kek, wrapped): # pragma: no cover - demo only
raise NotImplementedError
async def seal(self, recipient, pt, *, alg=None): # pragma: no cover - demo only
raise NotImplementedError
async def unseal(self, recipient_priv, sealed, *, alg=None): # pragma: no cover - demo only
raise NotImplementedError
async def main() -> None:
# Compose two providers that advertise different algorithms.
chacha = DummyCrypto("chacha", "CHACHA20-POLY1305")
aes = DummyCrypto("aes", "A256GCM")
composite = CompositeCrypto([chacha, aes])
key = KeyRef(
kid="k",
version=1,
type=KeyType.SYMMETRIC,
uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
material=b"\x00" * 32,
)
ciphertext = await composite.encrypt(key, b"payload", alg="A256GCM")
print(f"Selected provider: {ciphertext.ct.decode()}")
if __name__ == "__main__":
asyncio.run(main())
Entry point
The provider is registered under the swarmauri.cryptos entry-point as CompositeCrypto.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_crypto_composite-0.2.0.dev13.tar.gz.
File metadata
- Download URL: swarmauri_crypto_composite-0.2.0.dev13.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a425dd4022f81d9e158cb0a641d57a60ba1bd80fe2715d38c3cf8b00a8c3d05
|
|
| MD5 |
a2603dfaf1c7b529828dcdfbd0561667
|
|
| BLAKE2b-256 |
83e860addc7f500f047814f23e3d20e491045112610a2b6d366ff1ffd8e4bc24
|
File details
Details for the file swarmauri_crypto_composite-0.2.0.dev13-py3-none-any.whl.
File metadata
- Download URL: swarmauri_crypto_composite-0.2.0.dev13-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caa4c7868b344be5d85338c84f407238a143b75dcc8b3a4488a6d16cb4880f72
|
|
| MD5 |
15d49675aa1c19630e71466dbfb7b874
|
|
| BLAKE2b-256 |
d4cd89ec5b0785934c66cbb7dfdc4d1c5119ae0bcf68624d506287e7bcde9b76
|