-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
117 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// The possible types that a registry value could have. | ||
#[derive(Clone, PartialEq, Eq, Debug)] | ||
pub enum Type { | ||
/// A 32-bit unsigned integer value. | ||
U32, | ||
|
||
/// A 64-bit unsigned integer value. | ||
U64, | ||
|
||
/// A string value. | ||
String, | ||
|
||
/// An array u8 bytes. | ||
Bytes, | ||
|
||
/// An array of string values. | ||
MultiString, | ||
|
||
/// An unknown or unsupported type. | ||
Unknown(u32), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use windows::{core::w, Win32::System::Registry::*}; | ||
use windows_registry::*; | ||
|
||
#[test] | ||
fn bad_string() -> Result<()> { | ||
let bad_string_bytes = vec![ | ||
0x00, 0xD8, // leading surrogate | ||
0x01, 0x01, // bogus trailing surrogate | ||
0x00, 0x00, // null | ||
]; | ||
|
||
let test_key = "software\\windows-rs\\tests\\bad_string"; | ||
_ = CURRENT_USER.remove_tree(test_key); | ||
let key = CURRENT_USER.create(test_key)?; | ||
|
||
unsafe { | ||
RegSetValueExW( | ||
HKEY(key.as_raw()), | ||
w!("name"), | ||
0, | ||
REG_SZ, | ||
Some(&bad_string_bytes), | ||
) | ||
.ok()? | ||
}; | ||
|
||
let ty = key.get_type("name")?; | ||
assert_eq!(ty, Type::String); | ||
|
||
let value_as_string = key.get_string("name")?; | ||
assert_eq!(value_as_string, "�ā"); | ||
|
||
let value_as_bytes = key.get_bytes("name")?; | ||
assert_eq!(value_as_bytes, bad_string_bytes); | ||
Ok(()) | ||
} |