This release is a pre-release and may not be stable for production use.
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 encaps(self, recipient, *, alg=None): # pragma: no cover - demo only
raise NotImplementedError
async def decaps(self, recipient_priv, encapsulated_key, *, 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.
Metadata
Release files for swarmauri_crypto_composite 0.11.0.dev2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swarmauri_crypto_composite-0.11.0.dev2.tar.gz | 8.3 kB | Without provenance | Details for swarmauri_crypto_composite-0.11.0.dev2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmauri_crypto_composite-0.11.0.dev2-py3-none-any.whl | Python 3 | none | any | Details for swarmauri_crypto_composite-0.11.0.dev2-py3-none-any.whl |
Total release size: 17.7 kB
Release files / swarmauri_crypto_composite-0.11.0.dev2.tar.gz
| Download URL | swarmauri_crypto_composite-0.11.0.dev2.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b08a0902ee9fedee3d2ebc2575e9f154a558b391c6d38f47f062fa9ac26491e7
|
|
BLAKE2b-256 checksum How to use checksums |
51d9a308dd302741d3a51c393b090fff1becb3c43dbd3e5de325f5158a5f97aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
|
Release files / swarmauri_crypto_composite-0.11.0.dev2-py3-none-any.whl
| Download URL | swarmauri_crypto_composite-0.11.0.dev2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46997b3ba60c7dbcdf0e005883a994168d379e699531418def83331156ae1a70
|
|
BLAKE2b-256 checksum How to use checksums |
2412c7765e2ee0e8c1febc1ca321a80fa35e24fe764039188849b3e4387c4a8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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}
|
Security for swarmauri_crypto_composite 0.11.0.dev2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.