Skip to content

Commit f9d5d59

Browse files
youennfjan-ivar
andauthored
Expose SFrame errors through SFrameTransform.onerror (#103)
* Expose SFrame errors through SFrameTransform.onerror * Fix WebIDL * Queue a task * Update index.bs Co-authored-by: Jan-Ivar Bruaroey <[email protected]> * Update index.bs Co-authored-by: Jan-Ivar Bruaroey <[email protected]> * Update index.bs Co-authored-by: Jan-Ivar Bruaroey <[email protected]>
1 parent f616461 commit f9d5d59

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

index.bs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,30 @@ typedef (SmallCryptoKeyID or bigint) CryptoKeyID;
178178
interface SFrameTransform {
179179
constructor(optional SFrameTransformOptions options = {});
180180
Promise<undefined> setEncryptionKey(CryptoKey key, optional CryptoKeyID keyID);
181+
attribute EventHandler onerror;
181182
};
182183
SFrameTransform includes GenericTransformStream;
184+
185+
enum SFrameTransformErrorEventType {
186+
"authentication",
187+
"keyID",
188+
"syntax"
189+
};
190+
191+
[Exposed=(Window,DedicatedWorker)]
192+
interface SFrameTransformErrorEvent : Event {
193+
constructor(DOMString type, SFrameTransformErrorEventInit eventInitDict);
194+
195+
readonly attribute SFrameTransformErrorEventType type;
196+
readonly attribute CryptoKeyID? keyID;
197+
readonly attribute any frame;
198+
};
199+
200+
dictionary SFrameTransformErrorEventInit : EventInit {
201+
required SFrameTransformErrorEventType type;
202+
required any frame;
203+
CryptoKeyID? keyID;
204+
};
183205
</xmp>
184206

185207
The <dfn constructor for="SFrameTransform" lt="SFrameTransform(options)"><code>new SFrameTransform(<var>options</var>)</code></dfn> constructor steps are:
@@ -195,18 +217,29 @@ The <dfn constructor for="SFrameTransform" lt="SFrameTransform(options)"><code>n
195217

196218
The SFrame transform algorithm, given |sframe| as a SFrameTransform object and |frame|, runs these steps:
197219
1. Let |role| be |sframe|.`[[role]]`.
198-
2. If |frame|.`[[owner]]` is a {{RTCRtpSender}}, set |role| to 'encrypt'.
199-
3. If |frame|.`[[owner]]` is a {{RTCRtpReceiver}}, set |role| to 'decrypt'.
200-
4. Let |data| be undefined.
201-
5. If |frame| is a {{BufferSource}}, set |data| to |frame|.
202-
6. If |frame| is a {{RTCEncodedAudioFrame}}, set |data| to |frame|.{{RTCEncodedAudioFrame/data}}
203-
7. If |frame| is a {{RTCEncodedVideoFrame}}, set |data| to |frame|.{{RTCEncodedVideoFrame/data}}
204-
8. If |data| is undefined, abort these steps.
205-
9. Let |buffer| be the result of running the SFrame algorithm with |data| and |role| as parameters. This algorithm is defined by the <a href="https://datatracker.ietf.org/doc/draft-omara-sframe/">SFrame specification</a> and returns an {{ArrayBuffer}}.
206-
10. If |frame| is a {{BufferSource}}, set |frame| to |buffer|.
207-
11. If |frame| is a {{RTCEncodedAudioFrame}}, set |frame|.{{RTCEncodedAudioFrame/data}} to |buffer|.
208-
12. If |frame| is a {{RTCEncodedVideoFrame}}, set |frame|.{{RTCEncodedVideoFrame/data}} to |buffer|.
209-
13. [=ReadableStream/Enqueue=] |frame| in |sframe|.`[[transform]]`.
220+
1. If |frame|.`[[owner]]` is a {{RTCRtpSender}}, set |role| to 'encrypt'.
221+
1. If |frame|.`[[owner]]` is a {{RTCRtpReceiver}}, set |role| to 'decrypt'.
222+
1. Let |data| be undefined.
223+
1. If |frame| is a {{BufferSource}}, set |data| to |frame|.
224+
1. If |frame| is a {{RTCEncodedAudioFrame}}, set |data| to |frame|.{{RTCEncodedAudioFrame/data}}
225+
1. If |frame| is a {{RTCEncodedVideoFrame}}, set |data| to |frame|.{{RTCEncodedVideoFrame/data}}
226+
1. If |data| is undefined, abort these steps.
227+
1. Let |buffer| be the result of running the SFrame algorithm with |data| and |role| as parameters. This algorithm is defined by the <a href="https://datatracker.ietf.org/doc/draft-omara-sframe/">SFrame specification</a> and returns an {{ArrayBuffer}}.
228+
1. If the SFrame algorithm exits abruptly with an error, [=queue a task=] to run the following sub steps:
229+
1. If the processing fails on decryption side due to |data| not following the SFrame format, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
230+
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/type}} attribute set to {{SFrameTransformErrorEventType/syntax}}
231+
and its {{SFrameTransformErrorEvent/frame}} attribute set to |frame|.
232+
1. If the processing fails on decryption side due to the key identifier parsed in |data| being unknown, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
233+
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/type}} attribute set to {{SFrameTransformErrorEventType/keyID}},
234+
its {{SFrameTransformErrorEvent/frame}} attribute set to |frame| and its {{SFrameTransformErrorEvent/keyID}} attribute set to the keyID value parsed in the SFrame header.
235+
1. If the processing fails on decryption side due to validation of the authentication tag, [=fire an event=] named {{SFrameTransform/onerror|error}} at |sframe|,
236+
using the {{SFrameTransformErrorEvent}} interface with its {{SFrameTransformErrorEvent/type}} attribute set to {{SFrameTransformErrorEventType/authentication}}
237+
and its {{SFrameTransformErrorEvent/frame}} attribute set to |frame|.
238+
1. Abort these steps.
239+
1. If |frame| is a {{BufferSource}}, set |frame| to |buffer|.
240+
1. If |frame| is a {{RTCEncodedAudioFrame}}, set |frame|.{{RTCEncodedAudioFrame/data}} to |buffer|.
241+
1. If |frame| is a {{RTCEncodedVideoFrame}}, set |frame|.{{RTCEncodedVideoFrame/data}} to |buffer|.
242+
1. [=ReadableStream/Enqueue=] |frame| in |sframe|.`[[transform]]`.
210243

211244
## Methods ## {#sframe-transform-methods}
212245
The <dfn method for="SFrameTransform">setEncryptionKey(|key|, |keyID|)</dfn> method steps are:

0 commit comments

Comments
 (0)