MediaSigner 0.11.0.dev1__tar.gz → 0.11.1__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.
- mediasigner-0.11.1/MediaSigner/__init__.py +7 -0
- {mediasigner-0.11.0.dev1 → mediasigner-0.11.1}/MediaSigner/_signer.py +70 -69
- {mediasigner-0.11.0.dev1 → mediasigner-0.11.1}/MediaSigner/cli.py +3 -3
- mediasigner-0.11.1/NOTICE +7 -0
- mediasigner-0.11.1/PKG-INFO +498 -0
- mediasigner-0.11.1/README.md +446 -0
- {mediasigner-0.11.0.dev1 → mediasigner-0.11.1}/pyproject.toml +54 -4
- mediasigner-0.11.0.dev1/MediaSigner/__init__.py +0 -7
- mediasigner-0.11.0.dev1/PKG-INFO +0 -211
- mediasigner-0.11.0.dev1/README.md +0 -159
- {mediasigner-0.11.0.dev1 → mediasigner-0.11.1}/LICENSE +0 -0
|
@@ -45,13 +45,11 @@ except Exception: # pragma: no cover - plugin optional
|
|
|
45
45
|
pass
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
class
|
|
49
|
-
"""
|
|
50
|
-
High-level async facade that routes signing calls to registered plugins.
|
|
51
|
-
"""
|
|
48
|
+
class MediaVerifier(ComponentBase):
|
|
49
|
+
"""Route verification to the registered media signature backends."""
|
|
52
50
|
|
|
53
51
|
resource: Optional[str] = ResourceTypes.SIGNING.value
|
|
54
|
-
type: str = "
|
|
52
|
+
type: str = "MediaVerifier"
|
|
55
53
|
|
|
56
54
|
def __init__(self, key_provider: Optional[IKeyProvider] = None) -> None:
|
|
57
55
|
super().__init__()
|
|
@@ -59,7 +57,6 @@ class MediaSigner(ComponentBase):
|
|
|
59
57
|
self._plugins: MutableMapping[str, SigningBase] = {}
|
|
60
58
|
self._load_plugins()
|
|
61
59
|
|
|
62
|
-
# ------------------------------------------------------------------
|
|
63
60
|
def _load_plugins(self) -> None:
|
|
64
61
|
registry_entry = self.__class__._registry.get("SigningBase", {})
|
|
65
62
|
subtypes = registry_entry.get("subtypes", {})
|
|
@@ -87,57 +84,103 @@ class MediaSigner(ComponentBase):
|
|
|
87
84
|
f"No signing plugin registered for format '{fmt}'"
|
|
88
85
|
) from exc
|
|
89
86
|
|
|
90
|
-
|
|
91
|
-
async def sign_bytes(
|
|
87
|
+
async def verify_bytes(
|
|
92
88
|
self,
|
|
93
89
|
fmt: str,
|
|
94
|
-
key: KeyRef,
|
|
95
90
|
payload: bytes,
|
|
91
|
+
signatures: Sequence[Signature],
|
|
96
92
|
*,
|
|
97
|
-
|
|
93
|
+
require: Optional[Mapping[str, object]] = None,
|
|
98
94
|
opts: Optional[Mapping[str, object]] = None,
|
|
99
|
-
) ->
|
|
100
|
-
return await self._resolve(fmt).
|
|
101
|
-
|
|
95
|
+
) -> bool:
|
|
96
|
+
return await self._resolve(fmt).verify_bytes(
|
|
97
|
+
payload, signatures, require=require, opts=opts
|
|
102
98
|
)
|
|
103
99
|
|
|
104
|
-
async def
|
|
100
|
+
async def verify_digest(
|
|
105
101
|
self,
|
|
106
102
|
fmt: str,
|
|
107
|
-
key: KeyRef,
|
|
108
103
|
digest: bytes,
|
|
104
|
+
signatures: Sequence[Signature],
|
|
109
105
|
*,
|
|
110
|
-
|
|
106
|
+
require: Optional[Mapping[str, object]] = None,
|
|
111
107
|
opts: Optional[Mapping[str, object]] = None,
|
|
112
|
-
) ->
|
|
113
|
-
return await self._resolve(fmt).
|
|
114
|
-
|
|
108
|
+
) -> bool:
|
|
109
|
+
return await self._resolve(fmt).verify_digest(
|
|
110
|
+
digest, signatures, require=require, opts=opts
|
|
115
111
|
)
|
|
116
112
|
|
|
117
|
-
async def
|
|
113
|
+
async def verify_envelope(
|
|
118
114
|
self,
|
|
119
115
|
fmt: str,
|
|
120
|
-
|
|
116
|
+
env,
|
|
121
117
|
signatures: Sequence[Signature],
|
|
122
118
|
*,
|
|
119
|
+
canon: Optional[str] = None,
|
|
123
120
|
require: Optional[Mapping[str, object]] = None,
|
|
124
121
|
opts: Optional[Mapping[str, object]] = None,
|
|
125
122
|
) -> bool:
|
|
126
|
-
return await self._resolve(fmt).
|
|
127
|
-
|
|
123
|
+
return await self._resolve(fmt).verify_envelope(
|
|
124
|
+
env, signatures, canon=canon, require=require, opts=opts
|
|
128
125
|
)
|
|
129
126
|
|
|
130
|
-
async def
|
|
127
|
+
async def verify_stream(
|
|
131
128
|
self,
|
|
132
129
|
fmt: str,
|
|
133
|
-
|
|
130
|
+
payload: StreamPayload,
|
|
134
131
|
signatures: Sequence[Signature],
|
|
135
132
|
*,
|
|
136
133
|
require: Optional[Mapping[str, object]] = None,
|
|
137
134
|
opts: Optional[Mapping[str, object]] = None,
|
|
138
135
|
) -> bool:
|
|
139
|
-
return await self._resolve(fmt).
|
|
140
|
-
|
|
136
|
+
return await self._resolve(fmt).verify_stream(
|
|
137
|
+
payload, signatures, require=require, opts=opts
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
def supported_formats(self) -> Iterable[str]:
|
|
141
|
+
return tuple(self._plugins.keys())
|
|
142
|
+
|
|
143
|
+
def supports(
|
|
144
|
+
self, fmt: str, *, key_ref: Optional[str] = None
|
|
145
|
+
) -> Mapping[str, Iterable[str]]:
|
|
146
|
+
plugin = self._resolve(fmt)
|
|
147
|
+
if key_ref is not None:
|
|
148
|
+
try:
|
|
149
|
+
return plugin.supports(key_ref) # type: ignore[arg-type]
|
|
150
|
+
except TypeError:
|
|
151
|
+
pass
|
|
152
|
+
return plugin.supports()
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class MediaSigner(MediaVerifier):
|
|
156
|
+
"""Route signing and verification to registered backends."""
|
|
157
|
+
|
|
158
|
+
type: str = "MediaSigner"
|
|
159
|
+
|
|
160
|
+
async def sign_bytes(
|
|
161
|
+
self,
|
|
162
|
+
fmt: str,
|
|
163
|
+
key: KeyRef,
|
|
164
|
+
payload: bytes,
|
|
165
|
+
*,
|
|
166
|
+
alg: Optional[Alg] = None,
|
|
167
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
168
|
+
) -> Sequence[Signature]:
|
|
169
|
+
return await self._resolve(fmt).sign_bytes(
|
|
170
|
+
key, payload, alg=alg, opts=opts
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
async def sign_digest(
|
|
174
|
+
self,
|
|
175
|
+
fmt: str,
|
|
176
|
+
key: KeyRef,
|
|
177
|
+
digest: bytes,
|
|
178
|
+
*,
|
|
179
|
+
alg: Optional[Alg] = None,
|
|
180
|
+
opts: Optional[Mapping[str, object]] = None,
|
|
181
|
+
) -> Sequence[Signature]:
|
|
182
|
+
return await self._resolve(fmt).sign_digest(
|
|
183
|
+
key, digest, alg=alg, opts=opts
|
|
141
184
|
)
|
|
142
185
|
|
|
143
186
|
async def canonicalize_envelope(
|
|
@@ -178,45 +221,3 @@ class MediaSigner(ComponentBase):
|
|
|
178
221
|
return await self._resolve(fmt).sign_stream(
|
|
179
222
|
key, payload, alg=alg, opts=opts
|
|
180
223
|
)
|
|
181
|
-
|
|
182
|
-
async def verify_envelope(
|
|
183
|
-
self,
|
|
184
|
-
fmt: str,
|
|
185
|
-
env,
|
|
186
|
-
signatures: Sequence[Signature],
|
|
187
|
-
*,
|
|
188
|
-
canon: Optional[str] = None,
|
|
189
|
-
require: Optional[Mapping[str, object]] = None,
|
|
190
|
-
opts: Optional[Mapping[str, object]] = None,
|
|
191
|
-
) -> bool:
|
|
192
|
-
return await self._resolve(fmt).verify_envelope(
|
|
193
|
-
env, signatures, canon=canon, require=require, opts=opts
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
async def verify_stream(
|
|
197
|
-
self,
|
|
198
|
-
fmt: str,
|
|
199
|
-
payload: StreamPayload,
|
|
200
|
-
signatures: Sequence[Signature],
|
|
201
|
-
*,
|
|
202
|
-
require: Optional[Mapping[str, object]] = None,
|
|
203
|
-
opts: Optional[Mapping[str, object]] = None,
|
|
204
|
-
) -> bool:
|
|
205
|
-
return await self._resolve(fmt).verify_stream(
|
|
206
|
-
payload, signatures, require=require, opts=opts
|
|
207
|
-
)
|
|
208
|
-
|
|
209
|
-
# ------------------------------------------------------------------
|
|
210
|
-
def supported_formats(self) -> Iterable[str]:
|
|
211
|
-
return tuple(self._plugins.keys())
|
|
212
|
-
|
|
213
|
-
def supports(
|
|
214
|
-
self, fmt: str, *, key_ref: Optional[str] = None
|
|
215
|
-
) -> Mapping[str, Iterable[str]]:
|
|
216
|
-
plugin = self._resolve(fmt)
|
|
217
|
-
if key_ref is not None:
|
|
218
|
-
try:
|
|
219
|
-
return plugin.supports(key_ref) # type: ignore[arg-type]
|
|
220
|
-
except TypeError:
|
|
221
|
-
pass
|
|
222
|
-
return plugin.supports()
|
|
@@ -10,7 +10,7 @@ import sys
|
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
from typing import Any, Mapping, MutableMapping, Sequence
|
|
12
12
|
|
|
13
|
-
from . import MediaSigner
|
|
13
|
+
from . import MediaSigner, MediaVerifier
|
|
14
14
|
from swarmauri_core.signing.types import Signature
|
|
15
15
|
|
|
16
16
|
BytesLike = bytes | bytearray
|
|
@@ -171,7 +171,7 @@ async def _cmd_sign_bytes(args: argparse.Namespace) -> int:
|
|
|
171
171
|
|
|
172
172
|
|
|
173
173
|
async def _cmd_verify_bytes(args: argparse.Namespace) -> int:
|
|
174
|
-
|
|
174
|
+
verifier = MediaVerifier()
|
|
175
175
|
payload = _read_bytes(args.input)
|
|
176
176
|
sig_payload = _load_json_file(args.sigs)
|
|
177
177
|
if not isinstance(sig_payload, list):
|
|
@@ -182,7 +182,7 @@ async def _cmd_verify_bytes(args: argparse.Namespace) -> int:
|
|
|
182
182
|
]
|
|
183
183
|
opts = _load_json_file(args.opts)
|
|
184
184
|
require = _load_json_file(args.require)
|
|
185
|
-
ok = await
|
|
185
|
+
ok = await verifier.verify_bytes(
|
|
186
186
|
args.format,
|
|
187
187
|
payload,
|
|
188
188
|
signature_entries,
|