keyring-rs icon indicating copy to clipboard operation
keyring-rs copied to clipboard

Add store password and get password blob functions for windows

Open zschreur opened this issue 8 months ago • 2 comments

Because of how the credentials are converted from u8 to u16 when stored on windows, it is not possible to store a blob of data that is greater than CRED_MAX_CREDENTIAL_BLOB_SIZE / 2.

This PR provides a workaround by creating a set_password_blob and get_password_blob function. These functions take and return a Vec<u8>. This allows a client to do something like:

pub fn store_cred(service: &str, user: &str, password: &Vec<u8>) -> Result<()> {
    match keyring::Entry::new(service, key)?
        .get_credential()
        .downcast_ref::<keyring::windows::WinCredential>()
    {
        Some(win_credential) => {
            win_credential.set_password_blob(password)
        },
       // ...

The code for getting & setting with a Vec<u8> was pulled out of set_password and get_password, and then those functions are now making use of the new blob functions.

zschreur avatar Jun 06 '24 16:06 zschreur