nv_redfish/computer_system/secure_boot.rs
1// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//! Secure boot.
16
17use crate::schema::redfish::secure_boot::SecureBoot as SecureBootSchema;
18use crate::Error;
19use crate::NvBmc;
20use nv_redfish_core::Bmc;
21use nv_redfish_core::NavProperty;
22use std::convert::identity;
23use std::marker::PhantomData;
24use std::sync::Arc;
25
26#[doc(inline)]
27pub use crate::schema::redfish::secure_boot::SecureBootCurrentBootType;
28
29/// Secure boot.
30///
31/// Provides functions to access Secure Boot functions.
32pub struct SecureBoot<B: Bmc> {
33 data: Arc<SecureBootSchema>,
34 _marker: PhantomData<B>,
35}
36
37impl<B: Bmc> SecureBoot<B> {
38 /// Create a new secure boot handle.
39 pub(crate) async fn new(
40 bmc: &NvBmc<B>,
41 nav: &NavProperty<SecureBootSchema>,
42 ) -> Result<Self, Error<B>> {
43 nav.get(bmc.as_ref())
44 .await
45 .map_err(crate::Error::Bmc)
46 .map(|data| Self {
47 data,
48 _marker: PhantomData,
49 })
50 }
51
52 /// Get the raw schema data for the Secure boot.
53 #[must_use]
54 pub fn raw(&self) -> Arc<SecureBootSchema> {
55 self.data.clone()
56 }
57
58 /// Get an indication of whether UEFI Secure Boot is enabled.
59 #[must_use]
60 pub fn secure_boot_enable(&self) -> Option<bool> {
61 self.data.secure_boot_enable.and_then(identity)
62 }
63
64 /// The UEFI Secure Boot state during the current boot cycle.
65 #[must_use]
66 pub fn secure_boot_current_boot(&self) -> Option<SecureBootCurrentBootType> {
67 self.data.secure_boot_current_boot.and_then(identity)
68 }
69}