Skip to main content

windows_erg/registry/
types.rs

1//! Registry type definitions (Hive, Access, Wow64View).
2
3use windows::Win32::System::Registry::*;
4
5/// Registry hive identifiers.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum Hive {
8    /// HKEY_CLASSES_ROOT
9    ClassesRoot,
10    /// HKEY_CURRENT_USER
11    CurrentUser,
12    /// HKEY_LOCAL_MACHINE
13    LocalMachine,
14    /// HKEY_USERS
15    Users,
16    /// HKEY_CURRENT_CONFIG
17    CurrentConfig,
18}
19
20impl Hive {
21    pub(crate) fn as_hkey(&self) -> HKEY {
22        match self {
23            Hive::ClassesRoot => HKEY_CLASSES_ROOT,
24            Hive::CurrentUser => HKEY_CURRENT_USER,
25            Hive::LocalMachine => HKEY_LOCAL_MACHINE,
26            Hive::Users => HKEY_USERS,
27            Hive::CurrentConfig => HKEY_CURRENT_CONFIG,
28        }
29    }
30
31    pub(crate) fn as_short_name(&self) -> &'static str {
32        match self {
33            Hive::ClassesRoot => "HKCR",
34            Hive::CurrentUser => "HKCU",
35            Hive::LocalMachine => "HKLM",
36            Hive::Users => "HKU",
37            Hive::CurrentConfig => "HKCC",
38        }
39    }
40}
41
42/// Access rights for registry keys.
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44pub enum Access {
45    /// Read-only access
46    Read,
47    /// Write-only access
48    Write,
49    /// Read and write access
50    ReadWrite,
51    /// All access rights
52    AllAccess,
53}
54
55impl Access {
56    pub(crate) fn to_sam_flags(self) -> u32 {
57        match self {
58            Access::Read => KEY_READ.0,
59            Access::Write => KEY_WRITE.0,
60            Access::ReadWrite => KEY_READ.0 | KEY_WRITE.0,
61            Access::AllAccess => KEY_ALL_ACCESS.0,
62        }
63    }
64}
65
66/// WOW64 registry view options.
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68pub(crate) enum Wow64View {
69    /// 32-bit registry view
70    Key32,
71    /// 64-bit registry view
72    Key64,
73}
74
75impl Wow64View {
76    pub(crate) fn to_sam_flags(self) -> u32 {
77        match self {
78            Wow64View::Key32 => 0x0200, // KEY_WOW64_32KEY
79            Wow64View::Key64 => 0x0100, // KEY_WOW64_64KEY
80        }
81    }
82}