Skip to main content

servo_constellation_traits/structured_data/
serializable.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
5//! This module contains implementations in script that are serializable,
6//! as per <https://html.spec.whatwg.org/multipage/#serializable-objects>.
7//! The implementations are here instead of in script as they need to
8//! be passed through the Constellation.
9
10use std::cell::RefCell;
11use std::path::PathBuf;
12
13use euclid::default::Transform3D;
14use malloc_size_of_derive::MallocSizeOf;
15use net_traits::filemanager_thread::RelativePos;
16use pixels::SharedSnapshot;
17use rustc_hash::FxHashMap;
18use serde::{Deserialize, Serialize};
19use servo_base::id::{
20    BlobId, CryptoKeyId, DomExceptionId, DomMatrixId, DomPointId, DomQuadId, DomRectId, FileId,
21    FileListId, ImageBitmapId, ImageDataId, QuotaExceededErrorId,
22};
23use servo_url::ImmutableOrigin;
24use strum::EnumIter;
25use uuid::Uuid;
26use zeroize::{Zeroize, ZeroizeOnDrop};
27
28use super::StructuredSerializedData;
29
30pub(crate) trait BroadcastClone
31where
32    Self: Sized,
33{
34    /// The ID type that uniquely identify each value.
35    type Id: Eq + std::hash::Hash + Copy;
36    /// Clone this value so that it can be reused with a broadcast channel.
37    /// Only return None if cloning is impossible.
38    fn clone_for_broadcast(&self) -> Option<Self>;
39    /// The field from which to clone values.
40    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>>;
41    /// The field into which to place cloned values.
42    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>>;
43}
44
45/// All the DOM interfaces that can be serialized.
46///
47/// NOTE: Variants which are derived from other serializable interfaces must come before their
48/// parents because serialization is attempted in order of the variants.
49#[derive(Clone, Copy, Debug, EnumIter)]
50pub enum Serializable {
51    /// The `File` interface.
52    File,
53    /// The `FileList` interface.
54    FileList,
55    /// The `Blob` interface.
56    Blob,
57    /// The `DOMPoint` interface.
58    DomPoint,
59    /// The `DOMPointReadOnly` interface.
60    DomPointReadOnly,
61    /// The `DOMRect` interface.
62    DomRect,
63    /// The `DOMRectReadOnly` interface.
64    DomRectReadOnly,
65    /// The `DOMQuad` interface.
66    DomQuad,
67    /// The `DOMMatrix` interface.
68    DomMatrix,
69    /// The `DOMMatrixReadOnly` interface.
70    DomMatrixReadOnly,
71    /// The `QuotaExceededError` interface.
72    QuotaExceededError,
73    /// The `DOMException` interface.
74    DomException,
75    /// The `ImageBitmap` interface.
76    ImageBitmap,
77    /// The `ImageData` interface.
78    ImageData,
79    /// The `CryptoKey` interface.
80    CryptoKey,
81}
82
83impl Serializable {
84    pub(super) fn clone_values(
85        &self,
86    ) -> fn(&StructuredSerializedData, &mut StructuredSerializedData) {
87        match self {
88            Serializable::File => StructuredSerializedData::clone_all_of_type::<SerializableFile>,
89            Serializable::FileList => {
90                StructuredSerializedData::clone_all_of_type::<SerializableFileList>
91            },
92            Serializable::Blob => StructuredSerializedData::clone_all_of_type::<BlobImpl>,
93            Serializable::DomPoint => StructuredSerializedData::clone_all_of_type::<DomPoint>,
94            Serializable::DomPointReadOnly => {
95                StructuredSerializedData::clone_all_of_type::<DomPoint>
96            },
97            Serializable::DomRect => StructuredSerializedData::clone_all_of_type::<DomRect>,
98            Serializable::DomRectReadOnly => StructuredSerializedData::clone_all_of_type::<DomRect>,
99            Serializable::DomQuad => StructuredSerializedData::clone_all_of_type::<DomQuad>,
100            Serializable::DomMatrix => StructuredSerializedData::clone_all_of_type::<DomMatrix>,
101            Serializable::DomMatrixReadOnly => {
102                StructuredSerializedData::clone_all_of_type::<DomMatrix>
103            },
104            Serializable::DomException => {
105                StructuredSerializedData::clone_all_of_type::<DomException>
106            },
107            Serializable::ImageBitmap => {
108                StructuredSerializedData::clone_all_of_type::<SerializableImageBitmap>
109            },
110            Serializable::QuotaExceededError => {
111                StructuredSerializedData::clone_all_of_type::<SerializableQuotaExceededError>
112            },
113            Serializable::ImageData => {
114                StructuredSerializedData::clone_all_of_type::<SerializableImageData>
115            },
116            Serializable::CryptoKey => {
117                StructuredSerializedData::clone_all_of_type::<SerializableCryptoKey>
118            },
119        }
120    }
121}
122
123/// Message for communication between the constellation and a global managing broadcast channels.
124#[derive(Debug, Deserialize, Serialize)]
125pub struct BroadcastChannelMsg {
126    /// The origin of this message.
127    pub origin: ImmutableOrigin,
128    /// The name of the channel.
129    pub channel_name: String,
130    /// A data-holder for serialized data.
131    pub data: StructuredSerializedData,
132}
133
134impl Clone for BroadcastChannelMsg {
135    fn clone(&self) -> BroadcastChannelMsg {
136        BroadcastChannelMsg {
137            data: self.data.clone_for_broadcast(),
138            origin: self.origin.clone(),
139            channel_name: self.channel_name.clone(),
140        }
141    }
142}
143
144#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
145pub struct SerializableFile {
146    pub blob_impl: BlobImpl,
147    pub name: String,
148    pub modified: i64,
149}
150
151impl BroadcastClone for SerializableFile {
152    type Id = FileId;
153
154    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
155        &data.files
156    }
157
158    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
159        &mut data.files
160    }
161
162    fn clone_for_broadcast(&self) -> Option<Self> {
163        let blob_impl = self.blob_impl.clone_for_broadcast()?;
164        Some(SerializableFile {
165            blob_impl,
166            name: self.name.clone(),
167            modified: self.modified,
168        })
169    }
170}
171
172#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
173pub struct SerializableFileList {
174    pub files: Vec<SerializableFile>,
175}
176
177impl BroadcastClone for SerializableFileList {
178    type Id = FileListId;
179
180    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
181        &data.file_lists
182    }
183
184    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
185        &mut data.file_lists
186    }
187
188    fn clone_for_broadcast(&self) -> Option<Self> {
189        let files = self
190            .files
191            .iter()
192            .map(|file| file.clone_for_broadcast())
193            .collect::<Option<Vec<_>>>()?;
194        Some(SerializableFileList { files })
195    }
196}
197
198/// File-based blob
199#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
200pub struct FileBlob {
201    id: Uuid,
202    name: Option<PathBuf>,
203    cache: RefCell<Option<Vec<u8>>>,
204    size: u64,
205}
206
207impl FileBlob {
208    /// Create a new file blob.
209    pub fn new(id: Uuid, name: Option<PathBuf>, cache: Option<Vec<u8>>, size: u64) -> FileBlob {
210        FileBlob {
211            id,
212            name,
213            cache: RefCell::new(cache),
214            size,
215        }
216    }
217
218    /// Get the size of the file.
219    pub fn get_size(&self) -> u64 {
220        self.size
221    }
222
223    /// Get the cached file data, if any.
224    pub fn get_cache(&self) -> Option<Vec<u8>> {
225        self.cache.borrow().clone()
226    }
227
228    /// Cache data.
229    pub fn cache_bytes(&self, bytes: Vec<u8>) {
230        *self.cache.borrow_mut() = Some(bytes);
231    }
232
233    /// Get the file id.
234    pub fn get_id(&self) -> Uuid {
235        self.id
236    }
237}
238
239impl BroadcastClone for BlobImpl {
240    type Id = BlobId;
241
242    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
243        &data.blobs
244    }
245
246    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
247        &mut data.blobs
248    }
249
250    fn clone_for_broadcast(&self) -> Option<Self> {
251        let type_string = self.type_string();
252
253        if let BlobData::Memory(bytes) = self.blob_data() {
254            let blob_clone = BlobImpl::new_from_bytes(bytes.clone(), type_string);
255
256            // Note: we insert the blob at the original id,
257            // otherwise this will not match the storage key as serialized by SM in `serialized`.
258            // The clone has it's own new Id however.
259            return Some(blob_clone);
260        } else {
261            // Not panicking only because this is called from the constellation.
262            log::warn!("Serialized blob not in memory format(should never happen).");
263        }
264        None
265    }
266}
267
268/// The data backing a DOM Blob.
269#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
270pub struct BlobImpl {
271    /// UUID of the blob.
272    blob_id: BlobId,
273    /// Content-type string
274    type_string: String,
275    /// Blob data-type.
276    blob_data: BlobData,
277    /// Sliced blobs referring to this one.
278    slices: Vec<BlobId>,
279}
280
281/// Different backends of Blob
282#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
283pub enum BlobData {
284    /// File-based blob, whose content lives in the net process
285    File(FileBlob),
286    /// Memory-based blob, whose content lives in the script process
287    Memory(Vec<u8>),
288    /// Sliced blob, including parent blob-id and
289    /// relative positions of current slicing range,
290    /// IMPORTANT: The depth of tree is only two, i.e. the parent Blob must be
291    /// either File-based or Memory-based
292    Sliced(BlobId, RelativePos),
293}
294
295impl BlobImpl {
296    /// Construct memory-backed BlobImpl
297    pub fn new_from_bytes(bytes: Vec<u8>, type_string: String) -> BlobImpl {
298        let blob_id = BlobId::new();
299        let blob_data = BlobData::Memory(bytes);
300        BlobImpl {
301            blob_id,
302            type_string,
303            blob_data,
304            slices: vec![],
305        }
306    }
307
308    /// Construct file-backed BlobImpl from File ID
309    pub fn new_from_file(file_id: Uuid, name: PathBuf, size: u64, type_string: String) -> BlobImpl {
310        let blob_id = BlobId::new();
311        let blob_data = BlobData::File(FileBlob {
312            id: file_id,
313            name: Some(name),
314            cache: RefCell::new(None),
315            size,
316        });
317        BlobImpl {
318            blob_id,
319            type_string,
320            blob_data,
321            slices: vec![],
322        }
323    }
324
325    /// Construct a BlobImpl from a slice of a parent.
326    pub fn new_sliced(range: RelativePos, parent: BlobId, type_string: String) -> BlobImpl {
327        let blob_id = BlobId::new();
328        let blob_data = BlobData::Sliced(parent, range);
329        BlobImpl {
330            blob_id,
331            type_string,
332            blob_data,
333            slices: vec![],
334        }
335    }
336
337    /// Get a clone of the blob-id
338    pub fn blob_id(&self) -> BlobId {
339        self.blob_id
340    }
341
342    /// Get a clone of the type-string
343    pub fn type_string(&self) -> String {
344        self.type_string.clone()
345    }
346
347    /// Get a mutable ref to the data
348    pub fn blob_data(&self) -> &BlobData {
349        &self.blob_data
350    }
351
352    /// Get a mutable ref to the data
353    pub fn blob_data_mut(&mut self) -> &mut BlobData {
354        &mut self.blob_data
355    }
356}
357
358#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
359/// A serializable version of the DOMPoint/DOMPointReadOnly interface.
360pub struct DomPoint {
361    /// The x coordinate.
362    pub x: f64,
363    /// The y coordinate.
364    pub y: f64,
365    /// The z coordinate.
366    pub z: f64,
367    /// The w coordinate.
368    pub w: f64,
369}
370
371impl BroadcastClone for DomPoint {
372    type Id = DomPointId;
373
374    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
375        &data.points
376    }
377
378    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
379        &mut data.points
380    }
381
382    fn clone_for_broadcast(&self) -> Option<Self> {
383        Some(self.clone())
384    }
385}
386
387#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
388/// A serializable version of the DOMRect/DOMRectReadOnly interface.
389pub struct DomRect {
390    /// The x coordinate.
391    pub x: f64,
392    /// The y coordinate.
393    pub y: f64,
394    /// The width.
395    pub width: f64,
396    /// The height.
397    pub height: f64,
398}
399
400impl BroadcastClone for DomRect {
401    type Id = DomRectId;
402
403    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
404        &data.rects
405    }
406
407    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
408        &mut data.rects
409    }
410
411    fn clone_for_broadcast(&self) -> Option<Self> {
412        Some(self.clone())
413    }
414}
415
416#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
417/// A serializable version of the DOMQuad interface.
418pub struct DomQuad {
419    /// The first point.
420    pub p1: DomPoint,
421    /// The second point.
422    pub p2: DomPoint,
423    /// The third point.
424    pub p3: DomPoint,
425    /// The fourth point.
426    pub p4: DomPoint,
427}
428
429impl BroadcastClone for DomQuad {
430    type Id = DomQuadId;
431
432    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
433        &data.quads
434    }
435
436    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
437        &mut data.quads
438    }
439
440    fn clone_for_broadcast(&self) -> Option<Self> {
441        Some(self.clone())
442    }
443}
444
445#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
446/// A serializable version of the DOMMatrix/DOMMatrixReadOnly interface.
447pub struct DomMatrix {
448    /// The matrix.
449    pub matrix: Transform3D<f64>,
450    /// Whether this matrix represents a 2D transformation.
451    pub is_2d: bool,
452}
453
454impl BroadcastClone for DomMatrix {
455    type Id = DomMatrixId;
456
457    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
458        &data.matrices
459    }
460
461    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
462        &mut data.matrices
463    }
464
465    fn clone_for_broadcast(&self) -> Option<Self> {
466        Some(self.clone())
467    }
468}
469
470#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
471/// A serializable version of the DOMException interface.
472pub struct DomException {
473    pub message: String,
474    pub name: String,
475}
476
477impl BroadcastClone for DomException {
478    type Id = DomExceptionId;
479
480    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
481        &data.exceptions
482    }
483
484    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
485        &mut data.exceptions
486    }
487
488    fn clone_for_broadcast(&self) -> Option<Self> {
489        Some(self.clone())
490    }
491}
492
493#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
494/// A serializable version of the QuotaExceededError interface.
495pub struct SerializableQuotaExceededError {
496    pub dom_exception: DomException,
497    pub quota: Option<f64>,
498    pub requested: Option<f64>,
499}
500
501impl BroadcastClone for SerializableQuotaExceededError {
502    type Id = QuotaExceededErrorId;
503
504    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
505        &data.quota_exceeded_errors
506    }
507
508    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
509        &mut data.quota_exceeded_errors
510    }
511
512    fn clone_for_broadcast(&self) -> Option<Self> {
513        Some(self.clone())
514    }
515}
516
517#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
518/// A serializable version of the ImageBitmap interface.
519pub struct SerializableImageBitmap {
520    pub bitmap_data: SharedSnapshot,
521}
522
523impl BroadcastClone for SerializableImageBitmap {
524    type Id = ImageBitmapId;
525
526    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
527        &data.image_bitmaps
528    }
529
530    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
531        &mut data.image_bitmaps
532    }
533
534    fn clone_for_broadcast(&self) -> Option<Self> {
535        Some(self.clone())
536    }
537}
538
539#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
540pub struct SerializableImageData {
541    pub data: Vec<u8>,
542    pub width: u32,
543    pub height: u32,
544}
545
546impl BroadcastClone for SerializableImageData {
547    type Id = ImageDataId;
548
549    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
550        &data.image_data
551    }
552
553    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
554        &mut data.image_data
555    }
556
557    fn clone_for_broadcast(&self) -> Option<Self> {
558        Some(self.clone())
559    }
560}
561
562/// A serializable version of the `Algorithm` dictionary, used by the `SubtleCrypto` interface.
563#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
564pub struct SerializableAlgorithm {
565    pub name: String,
566}
567
568/// A serializable version of the `CShakeParams` dictionary, used by the `SubtleCrypto` interface.
569#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
570pub struct SerializableCShakeParams {
571    pub name: String,
572    pub output_length: u32,
573    pub function_name: Option<Vec<u8>>,
574    pub customization: Option<Vec<u8>>,
575}
576
577/// A serializable version of the `TurboShakeParams` dictionary, used by the `SubtleCrypto`
578/// interface.
579#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
580pub struct SerializableTurboShakeParams {
581    pub name: String,
582    pub output_length: u32,
583    pub domain_separation: Option<u8>,
584}
585
586/// A serializable version of the `DigestAlgorithm` type, used the `SubtleCrypto` interface.
587#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
588pub enum SerializableDigestAlgorithm {
589    Sha(SerializableAlgorithm),
590    Sha3(SerializableAlgorithm),
591    CShake(SerializableCShakeParams),
592    TurboShake(SerializableTurboShakeParams),
593}
594
595/// A serializable version of the `KeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
596#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
597pub struct SerializableKeyAlgorithm {
598    pub name: String,
599}
600
601/// A serializable version of the `RsaHashedKeyAlgorithm` dictionary, used the `SubtleCrypto`
602/// interface.
603#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
604pub struct SerializableRsaHashedKeyAlgorithm {
605    pub name: String,
606    pub modulus_length: u32,
607    pub public_exponent: Vec<u8>,
608    pub hash: SerializableDigestAlgorithm,
609}
610
611/// A serializable version of the `EcKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
612#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
613pub struct SerializableEcKeyAlgorithm {
614    pub name: String,
615    pub named_curve: String,
616}
617
618/// A serializable version of the `AesKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
619#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
620pub struct SerializableAesKeyAlgorithm {
621    pub name: String,
622    pub length: u16,
623}
624
625/// A serializable version of the `HmacKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
626#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
627pub struct SerializableHmacKeyAlgorithm {
628    pub name: String,
629    pub hash: SerializableDigestAlgorithm,
630    pub length: u32,
631}
632
633/// A serializable version of the `KeyAlgorithmAndDerivatives` type, used by the `SubtleCrypto`
634/// interface.
635#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
636pub enum SerializableKeyAlgorithmAndDerivatives {
637    KeyAlgorithm(SerializableKeyAlgorithm),
638    RsaHashedKeyAlgorithm(SerializableRsaHashedKeyAlgorithm),
639    EcKeyAlgorithm(SerializableEcKeyAlgorithm),
640    AesKeyAlgorithm(SerializableAesKeyAlgorithm),
641    HmacKeyAlgorithm(SerializableHmacKeyAlgorithm),
642}
643
644/// A serializable version of the `Handle` type, used by the `CryptoKey` interface.
645#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, Zeroize, ZeroizeOnDrop)]
646pub enum SerializableCryptoKeyHandle {
647    RsaPrivateKey(Vec<u8>),
648    RsaPublicKey(Vec<u8>),
649    P256PrivateKey(Vec<u8>),
650    P384PrivateKey(Vec<u8>),
651    P521PrivateKey(Vec<u8>),
652    P256PublicKey(Vec<u8>),
653    P384PublicKey(Vec<u8>),
654    P521PublicKey(Vec<u8>),
655    Ed25519PrivateKey(Vec<u8>),
656    Ed25519PublicKey(Vec<u8>),
657    X25519PrivateKey([u8; 32]),
658    X25519PublicKey([u8; 32]),
659    Aes128Key(Vec<u8>),
660    Aes192Key(Vec<u8>),
661    Aes256Key(Vec<u8>),
662    HkdfSecret(Vec<u8>),
663    Pbkdf2(Vec<u8>),
664    Hmac(Vec<u8>),
665    MlKem512PrivateKey((Vec<u8>, Vec<u8>)),
666    MlKem768PrivateKey((Vec<u8>, Vec<u8>)),
667    MlKem1024PrivateKey((Vec<u8>, Vec<u8>)),
668    MlKem512PublicKey(Vec<u8>),
669    MlKem768PublicKey(Vec<u8>),
670    MlKem1024PublicKey(Vec<u8>),
671    MlDsa44PrivateKey(Vec<u8>),
672    MlDsa65PrivateKey(Vec<u8>),
673    MlDsa87PrivateKey(Vec<u8>),
674    MlDsa44PublicKey(Vec<u8>),
675    MlDsa65PublicKey(Vec<u8>),
676    MlDsa87PublicKey(Vec<u8>),
677    ChaCha20Poly1305Key(Vec<u8>),
678    Argon2Password(Vec<u8>),
679}
680
681/// A serializable version of the `CryptoKey` interface.
682#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
683pub struct SerializableCryptoKey {
684    pub key_type: String,
685    pub extractable: bool,
686    pub algorithm: SerializableKeyAlgorithmAndDerivatives,
687    pub usages: Vec<String>,
688    pub handle: SerializableCryptoKeyHandle,
689}
690
691impl BroadcastClone for SerializableCryptoKey {
692    type Id = CryptoKeyId;
693
694    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
695        &data.crypto_keys
696    }
697
698    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
699        &mut data.crypto_keys
700    }
701
702    fn clone_for_broadcast(&self) -> Option<Self> {
703        Some(self.clone())
704    }
705}