Skip to main content

In-memory key provider for Swarmauri

Project description

Swamauri Logo

Swarmauri In‑Memory Key Provider

Volatile, in‑memory key provider for Swarmauri. All key material is kept strictly in process memory (no disk writes). Ideal for testing, CI, and ephemeral gateways.

Installation

pip install swarmauri_keyprovider_inmemory

Usage

Create and manage symmetric (or opaque/asymmetric placeholder) keys entirely in memory. The snippet below creates a new symmetric key and returns a KeyRef with material present when allowed by the export policy.

import asyncio
from swarmauri_keyprovider_inmemory import InMemoryKeyProvider
from swarmauri_core.keys.types import (
    KeySpec,
    KeyClass,
    KeyAlg,      # optional, not enforced by the provider
    KeyUse,
    ExportPolicy,
)


async def main() -> None:
    provider = InMemoryKeyProvider()

    # Create a symmetric key kept only in memory
    spec = KeySpec(
        klass=KeyClass.symmetric,
        alg=KeyAlg.AES256,                # optional hint – not strictly enforced
        uses=(KeyUse.ENCRYPT, KeyUse.DECRYPT),
        export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,  # material may be present
        label="session-key",
    )
    ref = await provider.create_key(spec)
    assert ref.kid and ref.version == 1
    # ref.material may be populated depending on export_policy

    # Rotate to get a new version, still in memory only
    ref2 = await provider.rotate_key(ref.kid)
    assert ref2.version == 2

    # List available versions
    versions = await provider.list_versions(ref.kid)
    print(versions)  # e.g., (1, 2)

    # Import existing key material
    imported = await provider.import_key(
        spec,
        material=b"\x00" * 32,
    )
    assert imported.version == 1

    # Fetch current version
    current = await provider.get_key(ref.kid)
    assert current.version == max(versions)

    # Destroy a specific version or the whole key
    await provider.destroy_key(ref.kid, version=1)   # delete only v1
    await provider.destroy_key(imported.kid)         # delete all versions

    # Utilities
    rand = await provider.random_bytes(16)
    okm = await provider.hkdf(b"ikm", salt=b"salt", info=b"ctx", length=32)
    print(len(rand), len(okm))


asyncio.run(main())

Capabilities

  • Class support: symmetric, asymmetric (opaque)
  • Features: create, import, rotate, destroy, list_versions, get_key, random_bytes, hkdf
  • No persistence: data is lost when the process exits
  • Not supported: JWK/JWKS export (will raise NotImplementedError)

Notes

  • Exported KeyRef.material presence depends on the ExportPolicy. Use ExportPolicy.NONE to prevent material from being surfaced to callers.
  • For gateways, set this provider as the default to keep keys off disk in development and CI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_keyprovider_inmemory-0.2.0.dev4.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_keyprovider_inmemory-0.2.0.dev4.tar.gz.

File metadata

File hashes

Hashes for swarmauri_keyprovider_inmemory-0.2.0.dev4.tar.gz
Algorithm Hash digest
SHA256 240f593b97cd9a97d7db80cfc8da2f8a695ca15a8000a84971c174b7a5517838
MD5 ab1315cf78842ef2e235801c9fbe3ee6
BLAKE2b-256 1c49126f29a64089ce3055b623a5ef4e08926afa2b26cd8810a2f43933edb1e7

See more details on using hashes here.

File details

Details for the file swarmauri_keyprovider_inmemory-0.2.0.dev4-py3-none-any.whl.

File metadata

File hashes

Hashes for swarmauri_keyprovider_inmemory-0.2.0.dev4-py3-none-any.whl
Algorithm Hash digest
SHA256 9e439b0c4aae66927053d2f8c36254e9df0cb5aceee9179b4a282577d3da96ed
MD5 acbdf2e0f47fad0136be3266b473df34
BLAKE2b-256 898f5fc2de71f53eed55d3d945b5f30f639df0846091f4b9fdadad15088305a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page