Search code examples
windowswinapirustrust-cargo

Why does a module from the WinApi crate not exist when its in the docs?


In the documentation it says that the function is in winapi::um::wincrypt::CryptDecrypt but when I install the crate and bring it in my project everything works fine until I try to call the function where I get the following error message:

error[E0433]: failed to resolve. Could not find `wincrypt` in `um`
  --> src\main.rs:68:39
   |
68 |  let decrypted_password = winapi::um::wincrypt::CryptDecrypt(password);
   |                                       ^^^^^^^^ Could not find `wincrypt` in `um`

My goal is to decrypt passwords from the "Local Data" file on my computer where Chrome stores passwords. I am using the Windows win32crypt API binding called winapi in Rust. I am trying to accomplish something similar to chromepass but in Rust.


Solution

  • From the crate-level documentation:

    Frequently asked questions

    Why am I getting errors about unresolved imports?

    Each module is gated on a feature flag, so you must enable the appropriate feature to gain access to those items. For example, if you want to use something from winapi::um::winuser you must enable the winuser feature.

    In this case, you need to add wincrypt:

    [target.'cfg(windows)'.dependencies]
    winapi = { version = "0.3", features = ["wincrypt"] }