Skip to main content

script_webcrypto/
traits.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use script_bindings::DomTypes;
6#[cfg(feature = "subtlecrypto")]
7use script_bindings::reflector::DomObject;
8#[cfg(feature = "subtlecrypto")]
9use script_bindings::tasks::TaskOnce;
10
11use crate::crypto::Crypto;
12#[cfg(feature = "subtlecrypto")]
13use crate::cryptokey::CryptoKey;
14#[cfg(feature = "subtlecrypto")]
15use crate::subtlecrypto::SubtleCrypto;
16
17// This trait enforces the equivalence of all local types with the types in DomTypes.
18#[cfg(feature = "subtlecrypto")]
19trait_set::trait_set! {
20    pub trait Equivalence = DomTypes<
21        Crypto = Crypto<Self>,
22        CryptoKey = CryptoKey<Self>,
23        SubtleCrypto = SubtleCrypto<Self>,
24        // General Bounds
25        GlobalScope: WebCryptoGlobalTrait<Self>>;
26}
27
28#[cfg(not(feature = "subtlecrypto"))]
29trait_set::trait_set! {
30    pub trait Equivalence = DomTypes<Crypto = Crypto<Self>>;
31}
32
33#[cfg(feature = "subtlecrypto")]
34pub trait WebCryptoGlobalTrait<D: DomTypes>: Sized + DomObject {
35    fn queue_crypto_task_source(&self, task: impl TaskOnce + 'static);
36    fn queue_dom_manipulation_task_source(&self, task: impl TaskOnce + 'static);
37}