Skip to content

Commit 7d62e4f

Browse files
committed
secret: Use safe-io
See async-rs/async-std#1050
1 parent b0dbf46 commit 7d62e4f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/portal/secret.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Implementation of the XDG secret portal.
22
//!
33
//! This is a modified copy from ASHPD.
4-
use std::{collections::HashMap, os::unix::prelude::AsRawFd};
4+
use std::{
5+
collections::HashMap,
6+
os::fd::{AsFd, AsRawFd, FromRawFd, IntoRawFd, OwnedFd},
7+
};
58

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

@@ -122,7 +125,10 @@ impl<'a> SecretProxy<'a> {
122125
async {
123126
match self
124127
.0
125-
.call_method("RetrieveSecret", &(Fd::from(fd.as_raw_fd()), &options))
128+
.call_method(
129+
"RetrieveSecret",
130+
&(Fd::from(fd.as_fd().as_raw_fd()), &options),
131+
)
126132
.await
127133
{
128134
Ok(_) => Ok(()),
@@ -147,8 +153,9 @@ pub async fn retrieve() -> Result<Secret, Error> {
147153
}?;
148154

149155
let (mut x1, x2) = UnixStream::pair()?;
150-
proxy.retrieve_secret(&x2).await?;
151-
drop(x2);
156+
let owned_x2 = unsafe { OwnedFd::from_raw_fd(x2.into_raw_fd()) };
157+
proxy.retrieve_secret(&owned_x2).await?;
158+
drop(owned_x2);
152159
let mut buf = Vec::new();
153160
x1.read_to_end(&mut buf).await?;
154161

0 commit comments

Comments
 (0)