mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 10:13:31 +00:00
Update cargo minor (#6121)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Hinton <hinton@users.noreply.github.com>
This commit is contained in:
@@ -7,8 +7,7 @@ use rand::RngCore;
|
||||
use retry::delay::Fixed;
|
||||
use sha2::{Digest, Sha256};
|
||||
use windows::{
|
||||
core::{factory, HSTRING},
|
||||
h,
|
||||
core::{factory, h, s, HSTRING},
|
||||
Foundation::IAsyncOperation,
|
||||
Security::{
|
||||
Credentials::{
|
||||
@@ -202,7 +201,7 @@ fn focus_security_prompt() -> Result<()> {
|
||||
retry::OperationResult::Retry(())
|
||||
}
|
||||
|
||||
let class_name = windows::s!("Credential Dialog Xaml Host");
|
||||
let class_name = s!("Credential Dialog Xaml Host");
|
||||
retry::retry_with_index(Fixed::from_millis(500), |current_try| {
|
||||
if current_try > 3 {
|
||||
return retry::OperationResult::Err(());
|
||||
|
||||
@@ -3,7 +3,7 @@ use widestring::{U16CString, U16String};
|
||||
use windows::{
|
||||
core::{PCWSTR, PWSTR},
|
||||
Win32::{
|
||||
Foundation::{GetLastError, ERROR_NOT_FOUND, FILETIME, WIN32_ERROR},
|
||||
Foundation::{ERROR_NOT_FOUND, FILETIME},
|
||||
Security::Credentials::{
|
||||
CredDeleteW, CredFree, CredReadW, CredWriteW, CREDENTIALW, CRED_FLAGS,
|
||||
CRED_PERSIST_ENTERPRISE, CRED_TYPE_GENERIC,
|
||||
@@ -32,9 +32,7 @@ pub fn get_password<'a>(service: &str, account: &str) -> Result<String> {
|
||||
unsafe { CredFree(credential as *mut _) };
|
||||
});
|
||||
|
||||
if !result.as_bool() {
|
||||
return Err(anyhow!(convert_error(unsafe { GetLastError() })));
|
||||
}
|
||||
result.map_err(|e| anyhow!(convert_error(e)))?;
|
||||
|
||||
let password = unsafe {
|
||||
U16String::from_ptr(
|
||||
@@ -67,9 +65,7 @@ pub fn get_password_keytar<'a>(service: &str, account: &str) -> Result<String> {
|
||||
unsafe { CredFree(credential as *mut _) };
|
||||
});
|
||||
|
||||
if !result.as_bool() {
|
||||
return Err(anyhow!(unsafe { GetLastError() }.0.to_string()));
|
||||
}
|
||||
result?;
|
||||
|
||||
let password = unsafe {
|
||||
std::str::from_utf8_unchecked(std::slice::from_raw_parts(
|
||||
@@ -107,10 +103,7 @@ pub fn set_password(service: &str, account: &str, password: &str) -> Result<()>
|
||||
UserName: PWSTR(user_name.as_mut_ptr()),
|
||||
};
|
||||
|
||||
let result = unsafe { CredWriteW(&credential, 0) };
|
||||
if !result.as_bool() {
|
||||
return Err(anyhow!(unsafe { GetLastError() }.0.to_string()));
|
||||
}
|
||||
unsafe { CredWriteW(&credential, 0) }?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -123,8 +116,7 @@ pub fn delete_password(service: &str, account: &str) -> Result<()> {
|
||||
PCWSTR(target_name.as_ptr()),
|
||||
CRED_TYPE_GENERIC.0,
|
||||
CRED_FLAGS_NONE,
|
||||
)
|
||||
.ok()?
|
||||
)?
|
||||
};
|
||||
|
||||
Ok(())
|
||||
@@ -135,11 +127,11 @@ fn target_name(service: &str, account: &str) -> String {
|
||||
}
|
||||
|
||||
// Convert the internal WIN32 errors to descriptive messages
|
||||
fn convert_error(code: WIN32_ERROR) -> String {
|
||||
match code {
|
||||
ERROR_NOT_FOUND => String::from("Password not found."),
|
||||
_ => code.0.to_string(),
|
||||
fn convert_error(e: windows::core::Error) -> String {
|
||||
if e == ERROR_NOT_FOUND.into() {
|
||||
return "Password not found.".to_string();
|
||||
}
|
||||
e.to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user