@@ -15,7 +15,8 @@ use uefi_raw::table::boot::MemoryDescriptor;
1515
1616#[ cfg( feature = "alloc" ) ]
1717use {
18- crate :: mem:: make_boxed, crate :: Guid , alloc:: borrow:: ToOwned , alloc:: boxed:: Box , alloc:: vec:: Vec ,
18+ crate :: mem:: make_boxed, crate :: CString16 , crate :: Guid , alloc:: borrow:: ToOwned ,
19+ alloc:: boxed:: Box , alloc:: vec:: Vec ,
1920} ;
2021
2122#[ cfg( all( feature = "unstable" , feature = "alloc" ) ) ]
@@ -303,15 +304,13 @@ impl Iterator for VariableKeys {
303304
304305 match result {
305306 Ok ( ( ) ) => {
306- // Copy the name buffer, truncated after the first null
307- // character (if one is present).
308- let name = if let Some ( nul_pos) = self . name . iter ( ) . position ( |c| * c == 0 ) {
309- self . name [ ..=nul_pos] . to_owned ( )
310- } else {
311- self . name . clone ( )
307+ // Convert the name to a `CStr16`, yielding an error if invalid.
308+ let Ok ( name) = CStr16 :: from_u16_until_nul ( & self . name ) else {
309+ return Some ( Err ( Status :: UNSUPPORTED . into ( ) ) ) ;
312310 } ;
311+
313312 Some ( Ok ( VariableKey {
314- name,
313+ name : name . to_owned ( ) ,
315314 vendor : self . vendor ,
316315 } ) )
317316 }
@@ -868,30 +867,26 @@ impl TryFrom<&[u8]> for Time {
868867#[ cfg( feature = "alloc" ) ]
869868#[ derive( Clone , Debug , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
870869pub struct VariableKey {
871- pub ( crate ) name : Vec < u16 > ,
872870 /// Unique identifier for the vendor.
873871 pub vendor : VariableVendor ,
872+
873+ /// Name of the variable, unique with the vendor namespace.
874+ pub name : CString16 ,
874875}
875876
876877#[ cfg( feature = "alloc" ) ]
877878impl VariableKey {
878879 /// Name of the variable.
880+ #[ deprecated = "Use the VariableKey.name field instead" ]
879881 pub fn name ( & self ) -> core:: result:: Result < & CStr16 , crate :: data_types:: FromSliceWithNulError > {
880- CStr16 :: from_u16_with_nul ( & self . name )
882+ Ok ( & self . name )
881883 }
882884}
883885
884886#[ cfg( feature = "alloc" ) ]
885887impl Display for VariableKey {
886888 fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
887- write ! ( f, "VariableKey {{ name: " ) ?;
888-
889- match self . name ( ) {
890- Ok ( name) => write ! ( f, "\" {name}\" " ) ?,
891- Err ( err) => write ! ( f, "Err({err:?})" ) ?,
892- }
893-
894- write ! ( f, ", vendor: " ) ?;
889+ write ! ( f, "VariableKey {{ name: \" {}\" , vendor: " , self . name) ?;
895890
896891 if self . vendor == VariableVendor :: GLOBAL_VARIABLE {
897892 write ! ( f, "GLOBAL_VARIABLE" ) ?;
0 commit comments