1
1
//! Implementation of the XDG secret portal.
2
2
//!
3
3
//! 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
+ } ;
5
8
6
9
#[ cfg( feature = "async-std" ) ]
7
10
use async_std:: { os:: unix:: net:: UnixStream , prelude:: * } ;
@@ -83,7 +86,7 @@ impl<'a> SecretProxy<'a> {
83
86
///
84
87
/// * `fd` - Writable file descriptor for transporting the secret.
85
88
#[ 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 > {
87
90
let options = RetrieveOptions :: default ( ) ;
88
91
let cnx = self . 0 . connection ( ) ;
89
92
@@ -122,7 +125,10 @@ impl<'a> SecretProxy<'a> {
122
125
async {
123
126
match self
124
127
. 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
+ )
126
132
. await
127
133
{
128
134
Ok ( _) => Ok ( ( ) ) ,
@@ -147,8 +153,9 @@ pub async fn retrieve() -> Result<Secret, Error> {
147
153
} ?;
148
154
149
155
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) ;
152
159
let mut buf = Vec :: new ( ) ;
153
160
x1. read_to_end ( & mut buf) . await ?;
154
161
0 commit comments