Skip to content

Commit

Permalink
secret: Use safe-io
Browse files Browse the repository at this point in the history
  • Loading branch information
A6GibKm authored and bilelmoussaoui committed Dec 26, 2022
1 parent b0dbf46 commit cb1c1b8
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/portal/secret.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Implementation of the XDG secret portal.
//!
//! This is a modified copy from ASHPD.
use std::{collections::HashMap, os::unix::prelude::AsRawFd};
use std::{
collections::HashMap,
os::fd::{AsFd, AsRawFd, FromRawFd, IntoRawFd, OwnedFd},
};

#[cfg(feature = "async-std")]
use async_std::{os::unix::net::UnixStream, prelude::*};
Expand Down Expand Up @@ -83,7 +86,7 @@ impl<'a> SecretProxy<'a> {
///
/// * `fd` - Writable file descriptor for transporting the secret.
#[doc(alias = "RetrieveSecret")]
pub async fn retrieve_secret(&self, fd: &impl AsRawFd) -> Result<(), Error> {
pub async fn retrieve_secret(&self, fd: &impl AsFd) -> Result<(), Error> {
let options = RetrieveOptions::default();
let cnx = self.0.connection();

Expand Down Expand Up @@ -122,7 +125,10 @@ impl<'a> SecretProxy<'a> {
async {
match self
.0
.call_method("RetrieveSecret", &(Fd::from(fd.as_raw_fd()), &options))
.call_method(
"RetrieveSecret",
&(Fd::from(fd.as_fd().as_raw_fd()), &options),
)
.await
{
Ok(_) => Ok(()),
Expand All @@ -147,8 +153,9 @@ pub async fn retrieve() -> Result<Secret, Error> {
}?;

let (mut x1, x2) = UnixStream::pair()?;
proxy.retrieve_secret(&x2).await?;
drop(x2);
let owned_x2 = unsafe { OwnedFd::from_raw_fd(x2.into_raw_fd()) };
proxy.retrieve_secret(&owned_x2).await?;
drop(owned_x2);
let mut buf = Vec::new();
x1.read_to_end(&mut buf).await?;

Expand Down

0 comments on commit cb1c1b8

Please sign in to comment.