swarmauri_keyprovider_file 0.2.1.dev24__tar.gz → 0.11.0.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,26 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swarmauri_keyprovider_file
3
- Version: 0.2.1.dev24
3
+ Version: 0.11.0.dev1
4
4
  Summary: File-backed key provider for Swarmauri
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Keywords: swarmauri,sdk,standards,keyprovider,file,key-management
8
8
  Author: Jacob Stewart
9
9
  Author-email: jacob@swarmauri.com
10
- Requires-Python: >=3.10,<3.13
10
+ Requires-Python: >=3.10,<3.15
11
11
  Classifier: License :: OSI Approved :: Apache Software License
12
12
  Classifier: Natural Language :: English
13
- Classifier: Programming Language :: Python :: 3.10
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
13
  Classifier: Development Status :: 3 - Alpha
18
14
  Classifier: Topic :: Security :: Cryptography
19
15
  Classifier: Intended Audience :: Developers
20
16
  Classifier: Programming Language :: Python
21
17
  Classifier: Programming Language :: Python :: 3
22
18
  Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Programming Language :: Python :: 3.14
23
24
  Provides-Extra: cbor
24
25
  Provides-Extra: jwks
25
26
  Requires-Dist: cbor2 ; extra == "cbor"
@@ -29,23 +30,21 @@ Requires-Dist: swarmauri_base
29
30
  Requires-Dist: swarmauri_core
30
31
  Description-Content-Type: text/markdown
31
32
 
32
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
33
-
33
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
34
34
 
35
35
  <p align="center">
36
- <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
37
- <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_file" alt="PyPI - Downloads"/></a>
36
+ <a href="https://pepy.tech/project/swarmauri_keyprovider_file/">
37
+ <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_file/month" alt="PyPI - Downloads"/></a>
38
38
  <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file/">
39
39
  <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file.svg"/></a>
40
40
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
41
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_file" alt="PyPI - Python Version"/></a>
41
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
42
42
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
43
43
  <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_file" alt="PyPI - License"/></a>
44
44
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
45
45
  <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_file?label=swarmauri_keyprovider_file&color=green" alt="PyPI - swarmauri_keyprovider_file"/></a>
46
- </p>
47
-
48
- ---
46
+ <a href="https://discord.gg/N4UpBuQv8T">
47
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
49
48
 
50
49
  # Swarmauri File Key Provider
51
50
 
@@ -115,7 +114,7 @@ async def run_example() -> str:
115
114
  asyncio.run(run_example())
116
115
  ```
117
116
 
118
- `FileKeyProvider` is asynchronous—every lifecycle method returns a
117
+ `FileKeyProvider` is asynchronous?every lifecycle method returns a
119
118
  `KeyRef`. Use `include_secret=True` when retrieving keys that allow private
120
119
  material export so symmetric key bytes are loaded from disk.
121
120
 
@@ -128,3 +127,5 @@ The provider registers under the `swarmauri.key_providers` entry point as `FileK
128
127
  If you want to contribute to swarmauri-sdk, read up on our
129
128
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
130
129
  that will help you get started.
130
+
131
+
@@ -1,20 +1,18 @@
1
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
-
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
3
2
 
4
3
  <p align="center">
5
- <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
6
- <img src="https://img.shields.io/pypi/dm/swarmauri_keyprovider_file" alt="PyPI - Downloads"/></a>
4
+ <a href="https://pepy.tech/project/swarmauri_keyprovider_file/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_file/month" alt="PyPI - Downloads"/></a>
7
6
  <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file/">
8
7
  <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file.svg"/></a>
9
8
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
10
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_keyprovider_file" alt="PyPI - Python Version"/></a>
9
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
11
10
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
12
11
  <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_file" alt="PyPI - License"/></a>
13
12
  <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
14
13
  <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_file?label=swarmauri_keyprovider_file&color=green" alt="PyPI - swarmauri_keyprovider_file"/></a>
15
- </p>
16
-
17
- ---
14
+ <a href="https://discord.gg/N4UpBuQv8T">
15
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
18
16
 
19
17
  # Swarmauri File Key Provider
20
18
 
@@ -84,7 +82,7 @@ async def run_example() -> str:
84
82
  asyncio.run(run_example())
85
83
  ```
86
84
 
87
- `FileKeyProvider` is asynchronous—every lifecycle method returns a
85
+ `FileKeyProvider` is asynchronous?every lifecycle method returns a
88
86
  `KeyRef`. Use `include_secret=True` when retrieving keys that allow private
89
87
  material export so symmetric key bytes are loaded from disk.
90
88
 
@@ -96,4 +94,5 @@ The provider registers under the `swarmauri.key_providers` entry point as `FileK
96
94
 
97
95
  If you want to contribute to swarmauri-sdk, read up on our
98
96
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
99
- that will help you get started.
97
+ that will help you get started.
98
+
@@ -1,24 +1,25 @@
1
1
  [project]
2
2
  name = "swarmauri_keyprovider_file"
3
- version = "0.2.1.dev24"
3
+ version = "0.11.0.dev1"
4
4
  description = "File-backed key provider for Swarmauri"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
- requires-python = ">=3.10,<3.13"
7
+ requires-python = ">=3.10,<3.15"
8
8
  authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
9
9
  classifiers = [
10
10
  "License :: OSI Approved :: Apache Software License",
11
11
  "Natural Language :: English",
12
- "Programming Language :: Python :: 3.10",
13
- "Programming Language :: Python :: 3.11",
14
- "Programming Language :: Python :: 3.12",
15
- "Programming Language :: Python :: 3.13",
16
12
  "Development Status :: 3 - Alpha",
17
13
  "Topic :: Security :: Cryptography",
18
14
  "Intended Audience :: Developers",
19
15
  "Programming Language :: Python",
20
16
  "Programming Language :: Python :: 3",
21
17
  "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
22
23
  ]
23
24
  dependencies = [
24
25
  "swarmauri_core",
@@ -35,27 +35,38 @@ def _hash_hex(b: bytes, nbytes: int = 16) -> str:
35
35
  return h.finalize().hex()[: 2 * nbytes]
36
36
 
37
37
 
38
+ def _serialization_option(container, name: Optional[str], default):
39
+ if not name:
40
+ return default
41
+ try:
42
+ return getattr(container, name)
43
+ except AttributeError as exc:
44
+ raise ValueError(f"Unsupported serialization option: {name}") from exc
45
+
46
+
38
47
  def _serialize_keypair(priv, spec: KeySpec) -> tuple[bytes, Optional[bytes]]:
39
48
  """Serialize private and public key material according to ``spec``."""
40
49
 
41
- encoding = (
42
- serialization.Encoding[spec.encoding]
43
- if spec.encoding
44
- else serialization.Encoding.PEM
50
+ encoding = _serialization_option(
51
+ serialization.Encoding,
52
+ spec.encoding,
53
+ serialization.Encoding.PEM,
45
54
  )
46
- public_format = (
47
- serialization.PublicFormat[spec.public_format]
48
- if spec.public_format
49
- else serialization.PublicFormat.SubjectPublicKeyInfo
55
+ public_format = _serialization_option(
56
+ serialization.PublicFormat,
57
+ spec.public_format,
58
+ serialization.PublicFormat.SubjectPublicKeyInfo,
59
+ )
60
+ public = priv.public_key().public_bytes(
61
+ encoding=encoding, format=public_format
50
62
  )
51
- public = priv.public_key().public_bytes(encoding=encoding, format=public_format)
52
63
 
53
64
  material: Optional[bytes] = None
54
65
  if spec.export_policy != ExportPolicy.PUBLIC_ONLY:
55
- private_format = (
56
- serialization.PrivateFormat[spec.private_format]
57
- if spec.private_format
58
- else serialization.PrivateFormat.PKCS8
66
+ private_format = _serialization_option(
67
+ serialization.PrivateFormat,
68
+ spec.private_format,
69
+ serialization.PrivateFormat.PKCS8,
59
70
  )
60
71
  if spec.encryption and spec.encryption != "NoEncryption":
61
72
  raise ValueError(f"Unsupported encryption: {spec.encryption}")
@@ -194,9 +205,14 @@ class FileKeyProvider(KeyProviderBase):
194
205
  sk = ed25519.Ed25519PrivateKey.generate()
195
206
  elif spec.alg == KeyAlg.X25519:
196
207
  sk = x25519.X25519PrivateKey.generate()
197
- elif spec.alg in (KeyAlg.RSA_OAEP_SHA256, KeyAlg.RSA_PSS_SHA256):
208
+ elif spec.alg in (
209
+ KeyAlg.RSA_OAEP_SHA256,
210
+ KeyAlg.RSA_PSS_SHA256,
211
+ ):
198
212
  bits = spec.size_bits or 3072
199
- sk = rsa.generate_private_key(public_exponent=65537, key_size=bits)
213
+ sk = rsa.generate_private_key(
214
+ public_exponent=65537, key_size=bits
215
+ )
200
216
  elif spec.alg == KeyAlg.ECDSA_P256_SHA256:
201
217
  sk = ec.generate_private_key(ec.SECP256R1())
202
218
  else:
@@ -225,7 +241,11 @@ class FileKeyProvider(KeyProviderBase):
225
241
  export_policy=spec.export_policy,
226
242
  public=public,
227
243
  material=material,
228
- tags={"label": spec.label, "alg": spec.alg.value, **(spec.tags or {})},
244
+ tags={
245
+ "label": spec.label,
246
+ "alg": spec.alg.value,
247
+ **(spec.tags or {}),
248
+ },
229
249
  fingerprint=self._fingerprint(
230
250
  public=public, material=material, kid=kid
231
251
  ),
@@ -261,7 +281,9 @@ class FileKeyProvider(KeyProviderBase):
261
281
  pub_out = public
262
282
  else:
263
283
  try:
264
- sk = serialization.load_pem_private_key(material, password=None)
284
+ sk = serialization.load_pem_private_key(
285
+ material, password=None
286
+ )
265
287
  pub_out = sk.public_key().public_bytes(
266
288
  serialization.Encoding.PEM,
267
289
  serialization.PublicFormat.SubjectPublicKeyInfo,
@@ -342,7 +364,9 @@ class FileKeyProvider(KeyProviderBase):
342
364
  sk = x25519.X25519PrivateKey.generate()
343
365
  elif alg in (KeyAlg.RSA_OAEP_SHA256, KeyAlg.RSA_PSS_SHA256):
344
366
  bits = int(ov.get("size_bits") or 3072)
345
- sk = rsa.generate_private_key(public_exponent=65537, key_size=bits)
367
+ sk = rsa.generate_private_key(
368
+ public_exponent=65537, key_size=bits
369
+ )
346
370
  elif alg == KeyAlg.ECDSA_P256_SHA256:
347
371
  sk = ec.generate_private_key(ec.SECP256R1())
348
372
  else:
@@ -383,7 +407,9 @@ class FileKeyProvider(KeyProviderBase):
383
407
  ),
384
408
  )
385
409
 
386
- async def destroy_key(self, kid: str, version: Optional[int] = None) -> bool:
410
+ async def destroy_key(
411
+ self, kid: str, version: Optional[int] = None
412
+ ) -> bool:
387
413
  with self._lock:
388
414
  kdir = self._key_dir(kid)
389
415
  if not kdir.exists():
@@ -407,7 +433,11 @@ class FileKeyProvider(KeyProviderBase):
407
433
  return True
408
434
 
409
435
  async def get_key(
410
- self, kid: str, version: Optional[int] = None, *, include_secret: bool = False
436
+ self,
437
+ kid: str,
438
+ version: Optional[int] = None,
439
+ *,
440
+ include_secret: bool = False,
411
441
  ) -> KeyRef:
412
442
  with self._lock:
413
443
  meta = self._read_meta(kid)
@@ -437,7 +467,9 @@ class FileKeyProvider(KeyProviderBase):
437
467
  try:
438
468
  obj = json.loads(pem_priv.read_text())
439
469
  if obj.get("kty") == "oct" and obj.get("k"):
440
- material = base64.urlsafe_b64decode(obj["k"] + "==")
470
+ material = base64.urlsafe_b64decode(
471
+ obj["k"] + "=="
472
+ )
441
473
  else:
442
474
  material = pem_priv.read_bytes()
443
475
  except json.JSONDecodeError:
@@ -478,7 +510,9 @@ class FileKeyProvider(KeyProviderBase):
478
510
  vs.sort()
479
511
  return tuple(vs)
480
512
 
481
- async def get_public_jwk(self, kid: str, version: Optional[int] = None) -> dict:
513
+ async def get_public_jwk(
514
+ self, kid: str, version: Optional[int] = None
515
+ ) -> dict:
482
516
  ref = await self.get_key(kid, version, include_secret=False)
483
517
  alg = KeyAlg(ref.tags["alg"])
484
518
 
@@ -493,7 +527,9 @@ class FileKeyProvider(KeyProviderBase):
493
527
  vdir = self._ver_dir(ref.kid, ref.version)
494
528
  pem_pub = vdir / "public.pem"
495
529
  if not pem_pub.exists():
496
- raise RuntimeError("Public material unavailable for asymmetric key")
530
+ raise RuntimeError(
531
+ "Public material unavailable for asymmetric key"
532
+ )
497
533
  pub_bytes = pem_pub.read_bytes()
498
534
  else:
499
535
  pub_bytes = ref.public
@@ -567,7 +603,9 @@ class FileKeyProvider(KeyProviderBase):
567
603
  async def random_bytes(self, n: int) -> bytes:
568
604
  return secrets.token_bytes(n)
569
605
 
570
- async def hkdf(self, ikm: bytes, *, salt: bytes, info: bytes, length: int) -> bytes:
606
+ async def hkdf(
607
+ self, ikm: bytes, *, salt: bytes, info: bytes, length: int
608
+ ) -> bytes:
571
609
  return HKDF(
572
610
  algorithm=hashes.SHA256(), length=length, salt=salt, info=info
573
611
  ).derive(ikm)
@@ -0,0 +1,56 @@
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
+
3
+ <p align="center">
4
+ <a href="https://pepy.tech/project/swarmauri_keyprovider_file/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_keyprovider_file/month" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file/swarmauri_keyprovider_file/examples/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_file/swarmauri_keyprovider_file/examples.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
9
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
+ <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_file" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_keyprovider_file/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_file?label=swarmauri_keyprovider_file&color=green" alt="PyPI - swarmauri_keyprovider_file"/></a>
14
+ </p>
15
+
16
+ # FileKeyProvider Examples
17
+
18
+ This example shows how to persist a symmetric key using `FileKeyProvider`.
19
+
20
+ ```python
21
+ import asyncio
22
+ from tempfile import TemporaryDirectory
23
+
24
+ from swarmauri_keyprovider_file import FileKeyProvider
25
+ from swarmauri_core.key_providers.types import (
26
+ ExportPolicy,
27
+ KeyAlg,
28
+ KeyClass,
29
+ KeySpec,
30
+ )
31
+ from swarmauri_core.crypto.types import KeyUse
32
+
33
+
34
+ async def run_example() -> str:
35
+ """Persist a symmetric key on disk using FileKeyProvider."""
36
+ with TemporaryDirectory() as tmp:
37
+ provider = FileKeyProvider(tmp)
38
+ spec = KeySpec(
39
+ klass=KeyClass.symmetric,
40
+ alg=KeyAlg.AES256_GCM,
41
+ uses=(KeyUse.ENCRYPT,),
42
+ export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
43
+ )
44
+ created = await provider.create_key(spec)
45
+ provider2 = FileKeyProvider(tmp)
46
+ loaded = await provider2.get_key(created.kid, include_secret=True)
47
+ assert loaded.material == created.material
48
+ return loaded.kid
49
+
50
+
51
+ if __name__ == "__main__":
52
+ print(asyncio.run(run_example()))
53
+ ```
54
+
55
+
56
+
@@ -1,38 +0,0 @@
1
- # FileKeyProvider Examples
2
-
3
- This example shows how to persist a symmetric key using `FileKeyProvider`.
4
-
5
- ```python
6
- import asyncio
7
- from tempfile import TemporaryDirectory
8
-
9
- from swarmauri_keyprovider_file import FileKeyProvider
10
- from swarmauri_core.key_providers.types import (
11
- ExportPolicy,
12
- KeyAlg,
13
- KeyClass,
14
- KeySpec,
15
- )
16
- from swarmauri_core.crypto.types import KeyUse
17
-
18
-
19
- async def run_example() -> str:
20
- """Persist a symmetric key on disk using FileKeyProvider."""
21
- with TemporaryDirectory() as tmp:
22
- provider = FileKeyProvider(tmp)
23
- spec = KeySpec(
24
- klass=KeyClass.symmetric,
25
- alg=KeyAlg.AES256_GCM,
26
- uses=(KeyUse.ENCRYPT,),
27
- export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
28
- )
29
- created = await provider.create_key(spec)
30
- provider2 = FileKeyProvider(tmp)
31
- loaded = await provider2.get_key(created.kid, include_secret=True)
32
- assert loaded.material == created.material
33
- return loaded.kid
34
-
35
-
36
- if __name__ == "__main__":
37
- print(asyncio.run(run_example()))
38
- ```