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    pub webkit_relative_path: String,
150}
151
152impl BroadcastClone for SerializableFile {
153    type Id = FileId;
154
155    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
156        &data.files
157    }
158
159    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
160        &mut data.files
161    }
162
163    fn clone_for_broadcast(&self) -> Option<Self> {
164        let blob_impl = self.blob_impl.clone_for_broadcast()?;
165        Some(SerializableFile {
166            blob_impl,
167            name: self.name.clone(),
168            modified: self.modified,
169            webkit_relative_path: self.webkit_relative_path.clone(),
170        })
171    }
172}
173
174#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
175pub struct SerializableFileList {
176    pub files: Vec<SerializableFile>,
177}
178
179impl BroadcastClone for SerializableFileList {
180    type Id = FileListId;
181
182    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
183        &data.file_lists
184    }
185
186    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
187        &mut data.file_lists
188    }
189
190    fn clone_for_broadcast(&self) -> Option<Self> {
191        let files = self
192            .files
193            .iter()
194            .map(|file| file.clone_for_broadcast())
195            .collect::<Option<Vec<_>>>()?;
196        Some(SerializableFileList { files })
197    }
198}
199
200/// File-based blob
201#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
202pub struct FileBlob {
203    id: Uuid,
204    name: Option<PathBuf>,
205    cache: RefCell<Option<Vec<u8>>>,
206    size: u64,
207}
208
209impl FileBlob {
210    /// Create a new file blob.
211    pub fn new(id: Uuid, name: Option<PathBuf>, cache: Option<Vec<u8>>, size: u64) -> FileBlob {
212        FileBlob {
213            id,
214            name,
215            cache: RefCell::new(cache),
216            size,
217        }
218    }
219
220    /// Get the size of the file.
221    pub fn get_size(&self) -> u64 {
222        self.size
223    }
224
225    /// Get the cached file data, if any.
226    pub fn get_cache(&self) -> Option<Vec<u8>> {
227        self.cache.borrow().clone()
228    }
229
230    /// Cache data.
231    pub fn cache_bytes(&self, bytes: Vec<u8>) {
232        *self.cache.borrow_mut() = Some(bytes);
233    }
234
235    /// Get the file id.
236    pub fn get_id(&self) -> Uuid {
237        self.id
238    }
239}
240
241impl BroadcastClone for BlobImpl {
242    type Id = BlobId;
243
244    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
245        &data.blobs
246    }
247
248    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
249        &mut data.blobs
250    }
251
252    fn clone_for_broadcast(&self) -> Option<Self> {
253        let type_string = self.type_string();
254
255        if let BlobData::Memory(bytes) = self.blob_data() {
256            let blob_clone = BlobImpl::new_from_bytes(bytes.clone(), type_string);
257
258            // Note: we insert the blob at the original id,
259            // otherwise this will not match the storage key as serialized by SM in `serialized`.
260            // The clone has it's own new Id however.
261            return Some(blob_clone);
262        } else {
263            // Not panicking only because this is called from the constellation.
264            log::warn!("Serialized blob not in memory format(should never happen).");
265        }
266        None
267    }
268}
269
270/// The data backing a DOM Blob.
271#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
272pub struct BlobImpl {
273    /// UUID of the blob.
274    blob_id: BlobId,
275    /// Content-type string
276    type_string: String,
277    /// Blob data-type.
278    blob_data: BlobData,
279    /// Sliced blobs referring to this one.
280    slices: Vec<BlobId>,
281}
282
283/// Different backends of Blob
284#[derive(Debug, Deserialize, MallocSizeOf, Serialize)]
285pub enum BlobData {
286    /// File-based blob, whose content lives in the net process
287    File(FileBlob),
288    /// Memory-based blob, whose content lives in the script process
289    Memory(Vec<u8>),
290    /// Sliced blob, including parent blob-id and
291    /// relative positions of current slicing range,
292    /// IMPORTANT: The depth of tree is only two, i.e. the parent Blob must be
293    /// either File-based or Memory-based
294    Sliced(BlobId, RelativePos),
295}
296
297impl BlobImpl {
298    /// Construct memory-backed BlobImpl
299    pub fn new_from_bytes(bytes: Vec<u8>, type_string: String) -> BlobImpl {
300        let blob_id = BlobId::new();
301        let blob_data = BlobData::Memory(bytes);
302        BlobImpl {
303            blob_id,
304            type_string,
305            blob_data,
306            slices: vec![],
307        }
308    }
309
310    /// Construct file-backed BlobImpl from File ID
311    pub fn new_from_file(file_id: Uuid, name: PathBuf, size: u64, type_string: String) -> BlobImpl {
312        let blob_id = BlobId::new();
313        let blob_data = BlobData::File(FileBlob {
314            id: file_id,
315            name: Some(name),
316            cache: RefCell::new(None),
317            size,
318        });
319        BlobImpl {
320            blob_id,
321            type_string,
322            blob_data,
323            slices: vec![],
324        }
325    }
326
327    /// Construct a BlobImpl from a slice of a parent.
328    pub fn new_sliced(range: RelativePos, parent: BlobId, type_string: String) -> BlobImpl {
329        let blob_id = BlobId::new();
330        let blob_data = BlobData::Sliced(parent, range);
331        BlobImpl {
332            blob_id,
333            type_string,
334            blob_data,
335            slices: vec![],
336        }
337    }
338
339    /// Get a clone of the blob-id
340    pub fn blob_id(&self) -> BlobId {
341        self.blob_id
342    }
343
344    /// Get a clone of the type-string
345    pub fn type_string(&self) -> String {
346        self.type_string.clone()
347    }
348
349    /// Get a mutable ref to the data
350    pub fn blob_data(&self) -> &BlobData {
351        &self.blob_data
352    }
353
354    /// Get a mutable ref to the data
355    pub fn blob_data_mut(&mut self) -> &mut BlobData {
356        &mut self.blob_data
357    }
358}
359
360#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
361/// A serializable version of the DOMPoint/DOMPointReadOnly interface.
362pub struct DomPoint {
363    /// The x coordinate.
364    pub x: f64,
365    /// The y coordinate.
366    pub y: f64,
367    /// The z coordinate.
368    pub z: f64,
369    /// The w coordinate.
370    pub w: f64,
371}
372
373impl BroadcastClone for DomPoint {
374    type Id = DomPointId;
375
376    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
377        &data.points
378    }
379
380    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
381        &mut data.points
382    }
383
384    fn clone_for_broadcast(&self) -> Option<Self> {
385        Some(self.clone())
386    }
387}
388
389#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
390/// A serializable version of the DOMRect/DOMRectReadOnly interface.
391pub struct DomRect {
392    /// The x coordinate.
393    pub x: f64,
394    /// The y coordinate.
395    pub y: f64,
396    /// The width.
397    pub width: f64,
398    /// The height.
399    pub height: f64,
400}
401
402impl BroadcastClone for DomRect {
403    type Id = DomRectId;
404
405    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
406        &data.rects
407    }
408
409    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
410        &mut data.rects
411    }
412
413    fn clone_for_broadcast(&self) -> Option<Self> {
414        Some(self.clone())
415    }
416}
417
418#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
419/// A serializable version of the DOMQuad interface.
420pub struct DomQuad {
421    /// The first point.
422    pub p1: DomPoint,
423    /// The second point.
424    pub p2: DomPoint,
425    /// The third point.
426    pub p3: DomPoint,
427    /// The fourth point.
428    pub p4: DomPoint,
429}
430
431impl BroadcastClone for DomQuad {
432    type Id = DomQuadId;
433
434    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
435        &data.quads
436    }
437
438    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
439        &mut data.quads
440    }
441
442    fn clone_for_broadcast(&self) -> Option<Self> {
443        Some(self.clone())
444    }
445}
446
447#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
448/// A serializable version of the DOMMatrix/DOMMatrixReadOnly interface.
449pub struct DomMatrix {
450    /// The matrix.
451    pub matrix: Transform3D<f64>,
452    /// Whether this matrix represents a 2D transformation.
453    pub is_2d: bool,
454}
455
456impl BroadcastClone for DomMatrix {
457    type Id = DomMatrixId;
458
459    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
460        &data.matrices
461    }
462
463    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
464        &mut data.matrices
465    }
466
467    fn clone_for_broadcast(&self) -> Option<Self> {
468        Some(self.clone())
469    }
470}
471
472#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
473/// A serializable version of the DOMException interface.
474pub struct DomException {
475    pub message: String,
476    pub name: String,
477}
478
479impl BroadcastClone for DomException {
480    type Id = DomExceptionId;
481
482    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
483        &data.exceptions
484    }
485
486    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
487        &mut data.exceptions
488    }
489
490    fn clone_for_broadcast(&self) -> Option<Self> {
491        Some(self.clone())
492    }
493}
494
495#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
496/// A serializable version of the QuotaExceededError interface.
497pub struct SerializableQuotaExceededError {
498    pub dom_exception: DomException,
499    pub quota: Option<f64>,
500    pub requested: Option<f64>,
501}
502
503impl BroadcastClone for SerializableQuotaExceededError {
504    type Id = QuotaExceededErrorId;
505
506    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
507        &data.quota_exceeded_errors
508    }
509
510    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
511        &mut data.quota_exceeded_errors
512    }
513
514    fn clone_for_broadcast(&self) -> Option<Self> {
515        Some(self.clone())
516    }
517}
518
519#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
520/// A serializable version of the ImageBitmap interface.
521pub struct SerializableImageBitmap {
522    pub bitmap_data: SharedSnapshot,
523}
524
525impl BroadcastClone for SerializableImageBitmap {
526    type Id = ImageBitmapId;
527
528    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
529        &data.image_bitmaps
530    }
531
532    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
533        &mut data.image_bitmaps
534    }
535
536    fn clone_for_broadcast(&self) -> Option<Self> {
537        Some(self.clone())
538    }
539}
540
541#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
542pub struct SerializableImageData {
543    pub data: Vec<u8>,
544    pub width: u32,
545    pub height: u32,
546}
547
548impl BroadcastClone for SerializableImageData {
549    type Id = ImageDataId;
550
551    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
552        &data.image_data
553    }
554
555    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
556        &mut data.image_data
557    }
558
559    fn clone_for_broadcast(&self) -> Option<Self> {
560        Some(self.clone())
561    }
562}
563
564/// A serializable version of the `Algorithm` dictionary, used by the `SubtleCrypto` interface.
565#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
566pub struct SerializableAlgorithm {
567    pub name: String,
568}
569
570/// A serializable version of the `CShakeParams` dictionary, used by the `SubtleCrypto` interface.
571#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
572pub struct SerializableCShakeParams {
573    pub name: String,
574    pub output_length: u32,
575    pub function_name: Option<Vec<u8>>,
576    pub customization: Option<Vec<u8>>,
577}
578
579/// A serializable version of the `TurboShakeParams` dictionary, used by the `SubtleCrypto`
580/// interface.
581#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
582pub struct SerializableTurboShakeParams {
583    pub name: String,
584    pub output_length: u32,
585    pub domain_separation: Option<u8>,
586}
587
588/// A serializable version of the `KangarooTwelvelParams` dictionary, used by the `SubtleCrypto`
589/// interface.
590#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
591pub struct SerializableKangarooTwelveParams {
592    pub name: String,
593    pub output_length: u32,
594    pub customization: Option<Vec<u8>>,
595}
596
597/// A serializable version of the `DigestAlgorithm` type, used the `SubtleCrypto` interface.
598#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
599pub enum SerializableDigestAlgorithm {
600    Sha(SerializableAlgorithm),
601    Sha3(SerializableAlgorithm),
602    CShake(SerializableCShakeParams),
603    TurboShake(SerializableTurboShakeParams),
604    KangarooTwelve(SerializableKangarooTwelveParams),
605}
606
607/// A serializable version of the `KeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
608#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
609pub struct SerializableKeyAlgorithm {
610    pub name: String,
611}
612
613/// A serializable version of the `RsaHashedKeyAlgorithm` dictionary, used the `SubtleCrypto`
614/// interface.
615#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
616pub struct SerializableRsaHashedKeyAlgorithm {
617    pub name: String,
618    pub modulus_length: u32,
619    pub public_exponent: Vec<u8>,
620    pub hash: SerializableDigestAlgorithm,
621}
622
623/// A serializable version of the `EcKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
624#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
625pub struct SerializableEcKeyAlgorithm {
626    pub name: String,
627    pub named_curve: String,
628}
629
630/// A serializable version of the `AesKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
631#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
632pub struct SerializableAesKeyAlgorithm {
633    pub name: String,
634    pub length: u16,
635}
636
637/// A serializable version of the `HmacKeyAlgorithm` dictionary, used the `SubtleCrypto` interface.
638#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
639pub struct SerializableHmacKeyAlgorithm {
640    pub name: String,
641    pub hash: SerializableDigestAlgorithm,
642    pub length: u32,
643}
644
645/// A serializable version of the `KeyAlgorithmAndDerivatives` type, used by the `SubtleCrypto`
646/// interface.
647#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
648pub enum SerializableKeyAlgorithmAndDerivatives {
649    KeyAlgorithm(SerializableKeyAlgorithm),
650    RsaHashedKeyAlgorithm(SerializableRsaHashedKeyAlgorithm),
651    EcKeyAlgorithm(SerializableEcKeyAlgorithm),
652    AesKeyAlgorithm(SerializableAesKeyAlgorithm),
653    HmacKeyAlgorithm(SerializableHmacKeyAlgorithm),
654}
655
656/// A serializable version of the `Handle` type, used by the `CryptoKey` interface.
657#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, Zeroize, ZeroizeOnDrop)]
658pub enum SerializableCryptoKeyHandle {
659    RsaPrivateKey(Vec<u8>),
660    RsaPublicKey(Vec<u8>),
661    P256PrivateKey(Vec<u8>),
662    P384PrivateKey(Vec<u8>),
663    P521PrivateKey(Vec<u8>),
664    P256PublicKey(Vec<u8>),
665    P384PublicKey(Vec<u8>),
666    P521PublicKey(Vec<u8>),
667    Ed25519PrivateKey([u8; 32]),
668    Ed25519PublicKey([u8; 32]),
669    X25519PrivateKey([u8; 32]),
670    X25519PublicKey([u8; 32]),
671    Aes128Key(Vec<u8>),
672    Aes192Key(Vec<u8>),
673    Aes256Key(Vec<u8>),
674    HkdfSecret(Vec<u8>),
675    Pbkdf2(Vec<u8>),
676    Hmac(Vec<u8>),
677    MlKem512PrivateKey(Vec<u8>),
678    MlKem768PrivateKey(Vec<u8>),
679    MlKem1024PrivateKey(Vec<u8>),
680    MlKem512PublicKey(Vec<u8>),
681    MlKem768PublicKey(Vec<u8>),
682    MlKem1024PublicKey(Vec<u8>),
683    MlDsa44PrivateKey(Vec<u8>),
684    MlDsa65PrivateKey(Vec<u8>),
685    MlDsa87PrivateKey(Vec<u8>),
686    MlDsa44PublicKey(Vec<u8>),
687    MlDsa65PublicKey(Vec<u8>),
688    MlDsa87PublicKey(Vec<u8>),
689    ChaCha20Poly1305Key(Vec<u8>),
690    Argon2Password(Vec<u8>),
691}
692
693/// A serializable version of the `CryptoKey` interface.
694#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize)]
695pub struct SerializableCryptoKey {
696    pub key_type: String,
697    pub extractable: bool,
698    pub algorithm: SerializableKeyAlgorithmAndDerivatives,
699    pub usages: Vec<String>,
700    pub handle: SerializableCryptoKeyHandle,
701}
702
703impl BroadcastClone for SerializableCryptoKey {
704    type Id = CryptoKeyId;
705
706    fn source(data: &StructuredSerializedData) -> &Option<FxHashMap<Self::Id, Self>> {
707        &data.crypto_keys
708    }
709
710    fn destination(data: &mut StructuredSerializedData) -> &mut Option<FxHashMap<Self::Id, Self>> {
711        &mut data.crypto_keys
712    }
713
714    fn clone_for_broadcast(&self) -> Option<Self> {
715        Some(self.clone())
716    }
717}