Accept raw REGSAM access masks in open/create key helpers#641
Accept raw REGSAM access masks in open/create key helpers#641benhillis wants to merge 2 commits into
Conversation
Introduce wil::reg::access_mask, a thin type implicitly constructible from either a named key_access value or a raw REGSAM mask. The open_*_key and create_*_key helpers now take access_mask instead of key_access, so callers can pass arbitrary access rights (e.g. KEY_QUERY_VALUE, KEY_READ | KEY_WOW64_64KEY) while existing key_access call sites continue to compile unchanged. get_access_flags now delegates to access_mask to keep a single mapping. Adds RegistryTests coverage for raw-mask open/create. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3e8f57d to
5bf5590
Compare
| static constexpr DWORD map_key_access(::wil::reg::key_access access) WI_NOEXCEPT | ||
| { | ||
| switch (access) | ||
| { | ||
| case ::wil::reg::key_access::read: | ||
| return KEY_READ; | ||
| case ::wil::reg::key_access::write: | ||
| return KEY_WRITE; | ||
| case ::wil::reg::key_access::readwrite: | ||
| return KEY_ALL_ACCESS; | ||
| case ::wil::reg::key_access::read64: | ||
| return KEY_READ | KEY_WOW64_64KEY; | ||
| case ::wil::reg::key_access::write64: | ||
| return KEY_WRITE | KEY_WOW64_64KEY; | ||
| case ::wil::reg::key_access::readwrite64: | ||
| return KEY_ALL_ACCESS | KEY_WOW64_64KEY; | ||
| } | ||
| FAIL_FAST(); | ||
| RESULT_NORETURN_RESULT(0); | ||
| } |
There was a problem hiding this comment.
Without thinking about it much... I wonder if it's time to just change key_access so its values just represent these values literally and then define enum flag operations for the type... That would allow us to keep using the key_access type and get rid of this new access_mask and just static_cast when we want the values.
There was a problem hiding this comment.
@keith-horton for his opinion since it seems @citelao is now at a different company
There was a problem hiding this comment.
I'm personally good with Ben's change. we had long conversations about this years ago and I don't recall the reasoning specifically why we landed on this model. I'm personally good with the current model.
| static constexpr DWORD map_key_access(::wil::reg::key_access access) WI_NOEXCEPT | ||
| { | ||
| switch (access) | ||
| { | ||
| case ::wil::reg::key_access::read: | ||
| return KEY_READ; | ||
| case ::wil::reg::key_access::write: | ||
| return KEY_WRITE; | ||
| case ::wil::reg::key_access::readwrite: | ||
| return KEY_ALL_ACCESS; | ||
| case ::wil::reg::key_access::read64: | ||
| return KEY_READ | KEY_WOW64_64KEY; | ||
| case ::wil::reg::key_access::write64: | ||
| return KEY_WRITE | KEY_WOW64_64KEY; | ||
| case ::wil::reg::key_access::readwrite64: | ||
| return KEY_ALL_ACCESS | KEY_WOW64_64KEY; | ||
| } | ||
| FAIL_FAST(); | ||
| RESULT_NORETURN_RESULT(0); | ||
| } |
There was a problem hiding this comment.
I'm personally good with Ben's change. we had long conversations about this years ago and I don't recall the reasoning specifically why we landed on this model. I'm personally good with the current model.
Adds an
access_masktype accepted by the open/create key helpers, implicitly constructible fromkey_accessor a raw REGSAM, so callers can pass custom access rights. Includes Catch2[registry]tests (and compile-time static_asserts) passing in normal & noexcept configs. Part of enabling WSL to drop its in-house registry helper in favor of wil::reg.