swarmauri_keyprovider_local 0.2.1.dev23__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.
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/PKG-INFO +22 -13
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/README.md +15 -8
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/pyproject.toml +7 -6
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/swarmauri_keyprovider_local/LocalKeyProvider.py +75 -26
- swarmauri_keyprovider_local-0.11.0.dev1/swarmauri_keyprovider_local/examples/README.md +52 -0
- swarmauri_keyprovider_local-0.2.1.dev23/swarmauri_keyprovider_local/examples/README.md +0 -34
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/swarmauri_keyprovider_local/__init__.py +0 -0
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/swarmauri_keyprovider_local/examples/__init__.py +0 -0
- {swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/swarmauri_keyprovider_local/examples/basic_usage.py +0 -0
{swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/PKG-INFO
RENAMED
|
@@ -1,39 +1,46 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: swarmauri_keyprovider_local
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
4
|
Summary: In-memory key provider for development and testing
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
7
7
|
Keywords: swarmauri,sdk,standards,keyprovider,local,key-management
|
|
8
8
|
Author: Jacob Stewart
|
|
9
9
|
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.
|
|
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
|
Requires-Dist: cryptography
|
|
24
25
|
Requires-Dist: swarmauri_base
|
|
25
26
|
Requires-Dist: swarmauri_core
|
|
26
27
|
Description-Content-Type: text/markdown
|
|
27
28
|
|
|
28
|
-

|
|
29
30
|
|
|
30
31
|
<p align="center">
|
|
31
|
-
<a href="https://
|
|
32
|
-
|
|
33
|
-
<a href="https://
|
|
34
|
-
|
|
35
|
-
<a href="https://pypi.org/project/swarmauri_keyprovider_local/"
|
|
36
|
-
|
|
32
|
+
<a href="https://pepy.tech/project/swarmauri_keyprovider_local/">
|
|
33
|
+
<img src="https://static.pepy.tech/badge/swarmauri_keyprovider_local/month" alt="PyPI - Downloads"/></a>
|
|
34
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local/">
|
|
35
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local.svg"/></a>
|
|
36
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
37
|
+
<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>
|
|
38
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
39
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_local" alt="PyPI - License"/></a>
|
|
40
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
41
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_local?label=swarmauri_keyprovider_local&color=green" alt="PyPI - swarmauri_keyprovider_local"/></a>
|
|
42
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
43
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
37
44
|
|
|
38
45
|
# Swarmauri Local Key Provider
|
|
39
46
|
|
|
@@ -133,3 +140,5 @@ derived = await provider.hkdf(b"ikm", salt=b"salt", info=b"context", length=32)
|
|
|
133
140
|
If you want to contribute to swarmauri-sdk, read up on our
|
|
134
141
|
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
135
142
|
that will help you get started.
|
|
143
|
+
|
|
144
|
+
|
{swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/README.md
RENAMED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<a href="https://
|
|
5
|
-
|
|
6
|
-
<a href="https://
|
|
7
|
-
|
|
8
|
-
<a href="https://pypi.org/project/swarmauri_keyprovider_local/"
|
|
9
|
-
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_keyprovider_local/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_keyprovider_local/month" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
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_local/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_local" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_local?label=swarmauri_keyprovider_local&color=green" alt="PyPI - swarmauri_keyprovider_local"/></a>
|
|
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>
|
|
10
16
|
|
|
11
17
|
# Swarmauri Local Key Provider
|
|
12
18
|
|
|
@@ -105,4 +111,5 @@ derived = await provider.hkdf(b"ikm", salt=b"salt", info=b"context", length=32)
|
|
|
105
111
|
|
|
106
112
|
If you want to contribute to swarmauri-sdk, read up on our
|
|
107
113
|
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
108
|
-
that will help you get started.
|
|
114
|
+
that will help you get started.
|
|
115
|
+
|
{swarmauri_keyprovider_local-0.2.1.dev23 → swarmauri_keyprovider_local-0.11.0.dev1}/pyproject.toml
RENAMED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_keyprovider_local"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
4
|
description = "In-memory key provider for development and testing"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
|
-
requires-python = ">=3.10,<3.
|
|
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",
|
|
@@ -17,7 +17,12 @@ from cryptography.hazmat.primitives.kdf.hkdf import HKDF
|
|
|
17
17
|
from cryptography.hazmat.primitives.asymmetric import ed25519, rsa, ec, x25519
|
|
18
18
|
|
|
19
19
|
from swarmauri_base.key_providers.KeyProviderBase import KeyProviderBase
|
|
20
|
-
from swarmauri_core.key_providers.types import
|
|
20
|
+
from swarmauri_core.key_providers.types import (
|
|
21
|
+
KeySpec,
|
|
22
|
+
KeyAlg,
|
|
23
|
+
KeyClass,
|
|
24
|
+
ExportPolicy,
|
|
25
|
+
)
|
|
21
26
|
from swarmauri_core.crypto.types import KeyRef
|
|
22
27
|
|
|
23
28
|
|
|
@@ -31,6 +36,15 @@ def _b64u(b: bytes) -> str:
|
|
|
31
36
|
return base64.urlsafe_b64encode(b).rstrip(b"=").decode("ascii")
|
|
32
37
|
|
|
33
38
|
|
|
39
|
+
def _serialization_option(container, name: Optional[str], default):
|
|
40
|
+
if not name:
|
|
41
|
+
return default
|
|
42
|
+
try:
|
|
43
|
+
return getattr(container, name)
|
|
44
|
+
except AttributeError as exc:
|
|
45
|
+
raise ValueError(f"Unsupported serialization option: {name}") from exc
|
|
46
|
+
|
|
47
|
+
|
|
34
48
|
def _serialize_keypair(priv, spec: KeySpec) -> tuple[bytes, Optional[bytes]]:
|
|
35
49
|
"""Serialize a private key and its public counterpart.
|
|
36
50
|
|
|
@@ -39,24 +53,26 @@ def _serialize_keypair(priv, spec: KeySpec) -> tuple[bytes, Optional[bytes]]:
|
|
|
39
53
|
RETURNS (Tuple[bytes, Optional[bytes]]): Private bytes and public bytes.
|
|
40
54
|
"""
|
|
41
55
|
|
|
42
|
-
encoding = (
|
|
43
|
-
serialization.Encoding
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
encoding = _serialization_option(
|
|
57
|
+
serialization.Encoding,
|
|
58
|
+
spec.encoding,
|
|
59
|
+
serialization.Encoding.PEM,
|
|
46
60
|
)
|
|
47
|
-
public_format = (
|
|
48
|
-
serialization.PublicFormat
|
|
49
|
-
|
|
50
|
-
|
|
61
|
+
public_format = _serialization_option(
|
|
62
|
+
serialization.PublicFormat,
|
|
63
|
+
spec.public_format,
|
|
64
|
+
serialization.PublicFormat.SubjectPublicKeyInfo,
|
|
65
|
+
)
|
|
66
|
+
public = priv.public_key().public_bytes(
|
|
67
|
+
encoding=encoding, format=public_format
|
|
51
68
|
)
|
|
52
|
-
public = priv.public_key().public_bytes(encoding=encoding, format=public_format)
|
|
53
69
|
|
|
54
70
|
material: Optional[bytes] = None
|
|
55
71
|
if spec.export_policy != ExportPolicy.PUBLIC_ONLY:
|
|
56
|
-
private_format = (
|
|
57
|
-
serialization.PrivateFormat
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
private_format = _serialization_option(
|
|
73
|
+
serialization.PrivateFormat,
|
|
74
|
+
spec.private_format,
|
|
75
|
+
serialization.PrivateFormat.PKCS8,
|
|
60
76
|
)
|
|
61
77
|
if spec.encryption and spec.encryption != "NoEncryption":
|
|
62
78
|
raise ValueError(f"Unsupported encryption: {spec.encryption}")
|
|
@@ -100,7 +116,14 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
100
116
|
return {
|
|
101
117
|
"class": ("sym", "asym"),
|
|
102
118
|
"algs": algs,
|
|
103
|
-
"features": (
|
|
119
|
+
"features": (
|
|
120
|
+
"create",
|
|
121
|
+
"rotate",
|
|
122
|
+
"import",
|
|
123
|
+
"jwks",
|
|
124
|
+
"hkdf",
|
|
125
|
+
"random",
|
|
126
|
+
),
|
|
104
127
|
}
|
|
105
128
|
|
|
106
129
|
async def create_key(self, spec: KeySpec) -> KeyRef:
|
|
@@ -119,7 +142,9 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
119
142
|
sk = x25519.X25519PrivateKey.generate()
|
|
120
143
|
elif spec.alg in (KeyAlg.RSA_OAEP_SHA256, KeyAlg.RSA_PSS_SHA256):
|
|
121
144
|
bits = spec.size_bits or 3072
|
|
122
|
-
sk = rsa.generate_private_key(
|
|
145
|
+
sk = rsa.generate_private_key(
|
|
146
|
+
public_exponent=65537, key_size=bits
|
|
147
|
+
)
|
|
123
148
|
elif spec.alg == KeyAlg.ECDSA_P256_SHA256:
|
|
124
149
|
sk = ec.generate_private_key(ec.SECP256R1())
|
|
125
150
|
else:
|
|
@@ -133,9 +158,17 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
133
158
|
uses=tuple(spec.uses),
|
|
134
159
|
export_policy=spec.export_policy,
|
|
135
160
|
public=public,
|
|
136
|
-
material=(
|
|
137
|
-
|
|
138
|
-
|
|
161
|
+
material=(
|
|
162
|
+
material if spec.export_policy != ExportPolicy.NONE else None
|
|
163
|
+
),
|
|
164
|
+
tags={
|
|
165
|
+
"label": spec.label,
|
|
166
|
+
"alg": spec.alg.value,
|
|
167
|
+
**(spec.tags or {}),
|
|
168
|
+
},
|
|
169
|
+
fingerprint=self._fingerprint(
|
|
170
|
+
public=public, material=material, kid=kid
|
|
171
|
+
),
|
|
139
172
|
)
|
|
140
173
|
self._store.setdefault(kid, {})[version] = ref
|
|
141
174
|
return ref
|
|
@@ -155,14 +188,18 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
155
188
|
uses=tuple(spec.uses),
|
|
156
189
|
export_policy=spec.export_policy,
|
|
157
190
|
public=public,
|
|
158
|
-
material=(
|
|
191
|
+
material=(
|
|
192
|
+
material if spec.export_policy != ExportPolicy.NONE else None
|
|
193
|
+
),
|
|
159
194
|
tags={
|
|
160
195
|
"label": spec.label,
|
|
161
196
|
"alg": spec.alg.value,
|
|
162
197
|
"imported": True,
|
|
163
198
|
**(spec.tags or {}),
|
|
164
199
|
},
|
|
165
|
-
fingerprint=self._fingerprint(
|
|
200
|
+
fingerprint=self._fingerprint(
|
|
201
|
+
public=public, material=material, kid=kid
|
|
202
|
+
),
|
|
166
203
|
)
|
|
167
204
|
self._store.setdefault(kid, {})[1] = ref
|
|
168
205
|
return ref
|
|
@@ -177,7 +214,9 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
177
214
|
alg = KeyAlg(base.tags["alg"])
|
|
178
215
|
spec = KeySpec(
|
|
179
216
|
klass=(
|
|
180
|
-
KeyClass.symmetric
|
|
217
|
+
KeyClass.symmetric
|
|
218
|
+
if alg == KeyAlg.AES256_GCM
|
|
219
|
+
else KeyClass.asymmetric
|
|
181
220
|
),
|
|
182
221
|
alg=alg,
|
|
183
222
|
size_bits=(spec_overrides or {}).get("size_bits"),
|
|
@@ -193,7 +232,9 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
193
232
|
self._store[kid][latest + 1] = rotated
|
|
194
233
|
return rotated
|
|
195
234
|
|
|
196
|
-
async def destroy_key(
|
|
235
|
+
async def destroy_key(
|
|
236
|
+
self, kid: str, version: Optional[int] = None
|
|
237
|
+
) -> bool:
|
|
197
238
|
bucket = self._store.get(kid)
|
|
198
239
|
if not bucket:
|
|
199
240
|
return False
|
|
@@ -222,7 +263,9 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
222
263
|
async def list_versions(self, kid: str) -> Tuple[int, ...]:
|
|
223
264
|
return tuple(sorted(self._store[kid].keys()))
|
|
224
265
|
|
|
225
|
-
async def get_public_jwk(
|
|
266
|
+
async def get_public_jwk(
|
|
267
|
+
self, kid: str, version: Optional[int] = None
|
|
268
|
+
) -> dict:
|
|
226
269
|
ref = await self.get_key(kid, version)
|
|
227
270
|
alg = KeyAlg(ref.tags["alg"])
|
|
228
271
|
if alg == KeyAlg.ED25519:
|
|
@@ -271,7 +314,11 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
271
314
|
"kid": f"{ref.kid}.{ref.version}",
|
|
272
315
|
}
|
|
273
316
|
if alg == KeyAlg.AES256_GCM:
|
|
274
|
-
return {
|
|
317
|
+
return {
|
|
318
|
+
"kty": "oct",
|
|
319
|
+
"alg": "A256GCM",
|
|
320
|
+
"kid": f"{ref.kid}.{ref.version}",
|
|
321
|
+
}
|
|
275
322
|
raise ValueError(f"Unsupported alg for JWK export: {alg}")
|
|
276
323
|
|
|
277
324
|
async def jwks(self, *, prefix_kids: Optional[str] = None) -> dict:
|
|
@@ -286,7 +333,9 @@ class LocalKeyProvider(KeyProviderBase):
|
|
|
286
333
|
async def random_bytes(self, n: int) -> bytes:
|
|
287
334
|
return secrets.token_bytes(n)
|
|
288
335
|
|
|
289
|
-
async def hkdf(
|
|
336
|
+
async def hkdf(
|
|
337
|
+
self, ikm: bytes, *, salt: bytes, info: bytes, length: int
|
|
338
|
+
) -> bytes:
|
|
290
339
|
return HKDF(
|
|
291
340
|
algorithm=hashes.SHA256(), length=length, salt=salt, info=info
|
|
292
341
|
).derive(ikm)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_keyprovider_local/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_keyprovider_local/month" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local/swarmauri_keyprovider_local/examples/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_keyprovider_local/swarmauri_keyprovider_local/examples.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
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_local/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_keyprovider_local" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_keyprovider_local/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_keyprovider_local?label=swarmauri_keyprovider_local&color=green" alt="PyPI - swarmauri_keyprovider_local"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
# LocalKeyProvider Examples
|
|
17
|
+
|
|
18
|
+
This example demonstrates creating and retrieving a symmetric key with `LocalKeyProvider`.
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
import asyncio
|
|
22
|
+
from swarmauri_keyprovider_local import LocalKeyProvider
|
|
23
|
+
from swarmauri_core.key_providers.types import (
|
|
24
|
+
ExportPolicy,
|
|
25
|
+
KeyAlg,
|
|
26
|
+
KeyClass,
|
|
27
|
+
KeySpec,
|
|
28
|
+
)
|
|
29
|
+
from swarmauri_core.crypto.types import KeyUse
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def run_example() -> str:
|
|
33
|
+
"""Create and retrieve a symmetric key using LocalKeyProvider."""
|
|
34
|
+
provider = LocalKeyProvider()
|
|
35
|
+
spec = KeySpec(
|
|
36
|
+
klass=KeyClass.symmetric,
|
|
37
|
+
alg=KeyAlg.AES256_GCM,
|
|
38
|
+
uses=(KeyUse.ENCRYPT,),
|
|
39
|
+
export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
|
|
40
|
+
)
|
|
41
|
+
created = await provider.create_key(spec)
|
|
42
|
+
fetched = await provider.get_key(created.kid, include_secret=True)
|
|
43
|
+
assert fetched.material is not None
|
|
44
|
+
return fetched.kid
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
print(asyncio.run(run_example()))
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# LocalKeyProvider Examples
|
|
2
|
-
|
|
3
|
-
This example demonstrates creating and retrieving a symmetric key with `LocalKeyProvider`.
|
|
4
|
-
|
|
5
|
-
```python
|
|
6
|
-
import asyncio
|
|
7
|
-
from swarmauri_keyprovider_local import LocalKeyProvider
|
|
8
|
-
from swarmauri_core.key_providers.types import (
|
|
9
|
-
ExportPolicy,
|
|
10
|
-
KeyAlg,
|
|
11
|
-
KeyClass,
|
|
12
|
-
KeySpec,
|
|
13
|
-
)
|
|
14
|
-
from swarmauri_core.crypto.types import KeyUse
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
async def run_example() -> str:
|
|
18
|
-
"""Create and retrieve a symmetric key using LocalKeyProvider."""
|
|
19
|
-
provider = LocalKeyProvider()
|
|
20
|
-
spec = KeySpec(
|
|
21
|
-
klass=KeyClass.symmetric,
|
|
22
|
-
alg=KeyAlg.AES256_GCM,
|
|
23
|
-
uses=(KeyUse.ENCRYPT,),
|
|
24
|
-
export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
|
|
25
|
-
)
|
|
26
|
-
created = await provider.create_key(spec)
|
|
27
|
-
fetched = await provider.get_key(created.kid, include_secret=True)
|
|
28
|
-
assert fetched.material is not None
|
|
29
|
-
return fetched.kid
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if __name__ == "__main__":
|
|
33
|
-
print(asyncio.run(run_example()))
|
|
34
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|