underhill_core/emuplat/
non_volatile_store.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Non-volatile store backed by the VMGS broker.
5
6use vmcore::non_volatile_store::NonVolatileStore;
7use vmgs_broker::non_volatile_store::EncryptionNotSupported;
8use vmgs_broker::non_volatile_store::VmgsNonVolatileStore;
9
10/// An API for interacting with VMGS as an opaque [`NonVolatileStore`]
11pub trait VmbsBrokerNonVolatileStore {
12    /// Return a new [`NonVolatileStore`] object backed by a particular VMGS
13    /// file-id.
14    fn as_non_volatile_store(
15        &self,
16        file_id: vmgs::FileId,
17        encrypted: bool,
18    ) -> Result<Box<dyn NonVolatileStore>, EncryptionNotSupported>;
19}
20
21impl VmbsBrokerNonVolatileStore for vmgs_broker::VmgsClient {
22    fn as_non_volatile_store(
23        &self,
24        file_id: vmgs::FileId,
25        encrypted: bool,
26    ) -> Result<Box<dyn NonVolatileStore>, EncryptionNotSupported> {
27        Ok(Box::new(VmgsNonVolatileStore::new(
28            self.clone(),
29            file_id,
30            encrypted,
31        )?))
32    }
33}