[SM-243] Upgrade windows-rs (#3516)

This commit is contained in:
Oscar Hinton 2022-10-24 11:46:50 +02:00 committed by GitHub
parent 67c4e34669
commit 9c292028e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 47 deletions

View File

@ -55,3 +55,51 @@ jobs:
- name: Run tests
run: |
npm run test
rust:
name: rust - ${{ matrix.os }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: Install gnome-keyring
if: ${{ matrix.os=='ubuntu-latest' }}
run: sudo apt-get install -y gnome-keyring dbus-x11
- name: Checkout repo
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846
- name: Install rust
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746
with:
toolchain: stable
profile: minimal
override: true
- name: Build
working-directory: ./apps/desktop/desktop_native
run: cargo build
- name: Test Ubuntu
if: ${{ matrix.os=='ubuntu-latest' }}
working-directory: ./apps/desktop/desktop_native
run: |
eval "$(dbus-launch --sh-syntax)"
mkdir -p ~/.cache
mkdir -p ~/.local/share/keyrings
eval "$(printf '\n' | gnome-keyring-daemon --unlock)"
eval "$(printf '\n' | /usr/bin/gnome-keyring-daemon --start)"
cargo test -- --test-threads=1
- name: Test Windows / macOS
if: ${{ matrix.os!='ubuntu-latest' }}
working-directory: ./apps/desktop/desktop_native
run: |
cargo test -- --test-threads=1

View File

@ -865,15 +865,15 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.32.0"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbedf6db9096bc2364adce0ae0aa636dcd89f3c3f2cd67947062aaf0ca2a10ec"
checksum = "f1c4bd0a50ac6020f65184721f758dba47bb9fbc2133df715ec74a237b26794a"
dependencies = [
"windows_aarch64_msvc 0.32.0",
"windows_i686_gnu 0.32.0",
"windows_i686_msvc 0.32.0",
"windows_x86_64_gnu 0.32.0",
"windows_x86_64_msvc 0.32.0",
"windows_aarch64_msvc 0.39.0",
"windows_i686_gnu 0.39.0",
"windows_i686_msvc 0.39.0",
"windows_x86_64_gnu 0.39.0",
"windows_x86_64_msvc 0.39.0",
]
[[package]]
@ -889,12 +889,6 @@ dependencies = [
"windows_x86_64_msvc 0.36.1",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
@ -902,10 +896,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
name = "windows_aarch64_msvc"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
checksum = "ec7711666096bd4096ffa835238905bb33fb87267910e154b18b44eaabb340f2"
[[package]]
name = "windows_i686_gnu"
@ -914,10 +908,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
name = "windows_i686_gnu"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
checksum = "763fc57100a5f7042e3057e7e8d9bdd7860d330070251a73d003563a3bb49e1b"
[[package]]
name = "windows_i686_msvc"
@ -926,10 +920,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
name = "windows_i686_msvc"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
checksum = "7bc7cbfe58828921e10a9f446fcaaf649204dcfe6c1ddd712c5eebae6bda1106"
[[package]]
name = "windows_x86_64_gnu"
@ -938,13 +932,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
name = "windows_x86_64_gnu"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
checksum = "6868c165637d653ae1e8dc4d82c25d4f97dd6605eaa8d784b5c6e0ab2a252b65"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "windows_x86_64_msvc"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e4d40883ae9cae962787ca76ba76390ffa29214667a111db9e0a1ad8377e809"

View File

@ -8,7 +8,9 @@ version = "0.0.0"
[lib]
crate-type = ["cdylib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default=[]
manual_test=[]
[dependencies]
anyhow = "1.0"
@ -22,8 +24,7 @@ napi-build = "2.0.1"
[target.'cfg(windows)'.dependencies]
widestring = "0.5.1"
windows = {version = "0.32.0", features = [
"alloc",
windows = {version = "0.39.0", features = [
"Foundation",
"Security_Credentials_UI",
"Storage_Streams",

View File

@ -1,4 +1,4 @@
use anyhow::{Result, bail};
use anyhow::{bail, Result};
pub fn prompt(_hwnd: Vec<u8>, _message: String) -> Result<bool> {
bail!("platform not supported");

View File

@ -1,4 +1,4 @@
use anyhow::{Result, bail};
use anyhow::{bail, Result};
pub fn prompt(_hwnd: Vec<u8>, _message: String) -> Result<bool> {
bail!("platform not supported");

View File

@ -8,10 +8,10 @@ use windows::{
System::WinRT::IUserConsentVerifierInterop,
UI::{
Input::KeyboardAndMouse::{
self, keybd_event, GetAsyncKeyState, SetFocus, KEYEVENTF_EXTENDEDKEY,
KEYEVENTF_KEYUP, VK_MENU,
keybd_event, GetAsyncKeyState, SetFocus, KEYEVENTF_EXTENDEDKEY, KEYEVENTF_KEYUP,
VK_MENU,
},
WindowsAndMessaging::{self, SetForegroundWindow},
WindowsAndMessaging::SetForegroundWindow,
},
},
};
@ -75,6 +75,7 @@ mod tests {
use super::*;
#[test]
#[cfg(feature = "manual_test")]
fn test_prompt() {
prompt(
vec![0, 0, 0, 0, 0, 0, 0, 0],
@ -84,6 +85,7 @@ mod tests {
}
#[test]
#[cfg(feature = "manual_test")]
fn test_available() {
assert!(available().unwrap())
}

View File

@ -1,10 +1,13 @@
use anyhow::{anyhow, Result};
use widestring::{U16CString, U16String};
use windows::Win32::{
Foundation::{GetLastError, ERROR_NOT_FOUND, FILETIME, PWSTR, WIN32_ERROR},
Security::Credentials::{
CredDeleteW, CredFree, CredReadW, CredWriteW, CREDENTIALW, CRED_FLAGS,
CRED_PERSIST_ENTERPRISE, CRED_TYPE_GENERIC,
use windows::{
core::{PCWSTR, PWSTR},
Win32::{
Foundation::{GetLastError, ERROR_NOT_FOUND, FILETIME, WIN32_ERROR},
Security::Credentials::{
CredDeleteW, CredFree, CredReadW, CredWriteW, CREDENTIALW, CRED_FLAGS,
CRED_PERSIST_ENTERPRISE, CRED_TYPE_GENERIC,
},
},
};
@ -18,7 +21,7 @@ pub fn get_password<'a>(service: &str, account: &str) -> Result<String> {
let result = unsafe {
CredReadW(
PWSTR(target_name.as_ptr()),
PCWSTR(target_name.as_ptr()),
CRED_TYPE_GENERIC.0,
CRED_FLAGS_NONE,
credential_ptr,
@ -53,7 +56,7 @@ pub fn get_password_keytar<'a>(service: &str, account: &str) -> Result<String> {
let result = unsafe {
CredReadW(
PWSTR(target_name.as_ptr()),
PCWSTR(target_name.as_ptr()),
CRED_TYPE_GENERIC.0,
CRED_FLAGS_NONE,
credential_ptr,
@ -79,8 +82,8 @@ pub fn get_password_keytar<'a>(service: &str, account: &str) -> Result<String> {
}
pub fn set_password(service: &str, account: &str, password: &str) -> Result<()> {
let target_name = U16CString::from_str(target_name(service, account))?;
let user_name = U16CString::from_str(account)?;
let mut target_name = U16CString::from_str(target_name(service, account))?;
let mut user_name = U16CString::from_str(account)?;
let last_written = FILETIME {
dwLowDateTime: 0,
dwHighDateTime: 0,
@ -92,16 +95,16 @@ pub fn set_password(service: &str, account: &str, password: &str) -> Result<()>
let credential = CREDENTIALW {
Flags: CRED_FLAGS(CRED_FLAGS_NONE),
Type: CRED_TYPE_GENERIC,
TargetName: PWSTR(target_name.as_ptr()),
Comment: PWSTR::default(),
TargetName: PWSTR(unsafe { target_name.as_mut_ptr() }),
Comment: PWSTR::null(),
LastWritten: last_written,
CredentialBlobSize: credential_len,
CredentialBlob: credential.as_ptr() as *mut u8,
Persist: CRED_PERSIST_ENTERPRISE,
AttributeCount: 0,
Attributes: std::ptr::null_mut(),
TargetAlias: PWSTR::default(),
UserName: PWSTR(user_name.as_ptr()),
TargetAlias: PWSTR::null(),
UserName: PWSTR(unsafe { user_name.as_mut_ptr() }),
};
let result = unsafe { CredWriteW(&credential, 0) };
@ -117,7 +120,7 @@ pub fn delete_password(service: &str, account: &str) -> Result<()> {
unsafe {
CredDeleteW(
PWSTR(target_name.as_ptr()),
PCWSTR(target_name.as_ptr()),
CRED_TYPE_GENERIC.0,
CRED_FLAGS_NONE,
)