Skip to content

Commit 6f08d11

Browse files
committed
add get_info wrapper
1 parent b9e9fea commit 6f08d11

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/proto/rng.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
//! `Rng` protocol.
22
3-
use crate::{data_types::Guid, proto::Protocol, unsafe_guid, Status};
3+
use crate::{data_types::Guid, proto::Protocol, unsafe_guid, Result, Status};
4+
use core::slice::SliceIndex;
45

56
/// Contain a Rng algorithm Guid
67
#[repr(C)]
7-
struct RngAlgorithm(Guid);
8+
#[derive(Clone, Copy, Debug)]
9+
pub struct RngAlgorithm(pub Guid);
10+
11+
impl RngAlgorithm {
12+
pub fn default() -> Self {
13+
Self(Guid::default())
14+
}
15+
}
816

917
/// Rng protocol
1018
#[repr(C)]
@@ -24,9 +32,13 @@ pub struct Rng {
2432
) -> Status,
2533
}
2634

27-
/*impl Rng {
28-
fn get_info(&mut self) -> Result<[RngAlgorithm]> {
29-
let mut algorithm_list_size: usize;
30-
let mut algorithm_list: []
35+
impl Rng {
36+
pub fn get_info(&mut self, algorithm_list: &mut [RngAlgorithm]) -> Result<usize> {
37+
let mut algorithm_list_size = (algorithm_list.len() * 16) as *mut usize;
38+
39+
(self.get_info)(self, algorithm_list_size, algorithm_list.as_mut_ptr())
40+
.into_with_val(|| algorithm_list_size as usize / 16)
41+
42+
// TODO: Add AlgorithmType Enum for better visibility on algorithms
3143
}
32-
}*/
44+
}

uefi-test-runner/src/proto/rng.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use core::mem;
2+
use core::mem::size_of_val;
13
use uefi::prelude::*;
2-
use uefi::proto::rng::Rng;
4+
use uefi::proto::rng::{Rng, RngAlgorithm};
35
use uefi::table::boot::{BootServices, OpenProtocolAttributes, OpenProtocolParams};
6+
use uefi::Guid;
47

58
pub fn test(image: Handle, bt: &BootServices) {
69
info!("Running rng protocol test");
@@ -21,5 +24,18 @@ pub fn test(image: Handle, bt: &BootServices) {
2124
OpenProtocolAttributes::Exclusive,
2225
)
2326
.expect_success("Failed to open Rng protocol");
24-
let _rng = unsafe { &*rng.interface.get() };
27+
let rng = unsafe { &mut *rng.interface.get() };
28+
29+
let mut list = [RngAlgorithm::default(); 4];
30+
31+
match rng.get_info(&mut list) {
32+
Ok(nb) => {
33+
for i in 0..nb.unwrap() {
34+
info!("OK {} : {}", nb.unwrap(), list[i].0)
35+
}
36+
}
37+
Err(e) => {
38+
error!("ERROR : {:#?}", e.status())
39+
}
40+
}
2541
}

0 commit comments

Comments
 (0)