@@ -36,6 +36,7 @@ use hid_io_protocol::{HidIoCommandId, HidIoPacketType};
36
36
use rcgen:: generate_simple_self_signed;
37
37
use std:: collections:: HashMap ;
38
38
use std:: env;
39
+ use std:: fs:: File ;
39
40
use std:: io:: Write ;
40
41
use std:: net:: ToSocketAddrs ;
41
42
use std:: sync:: atomic:: Ordering ;
@@ -119,7 +120,7 @@ struct HidIoServerImpl {
119
120
basic_key : String ,
120
121
auth_key : String ,
121
122
122
- basic_key_file : tempfile:: NamedTempFile ,
123
+ basic_key_dir : tempfile:: TempDir ,
123
124
auth_key_file : tempfile:: NamedTempFile ,
124
125
125
126
subscriptions : Arc < RwLock < Subscriptions > > ,
@@ -133,15 +134,16 @@ impl HidIoServerImpl {
133
134
subscriptions : Arc < RwLock < Subscriptions > > ,
134
135
) -> HidIoServerImpl {
135
136
// Create temp file for basic key
136
- let mut basic_key_file = tempfile:: Builder :: new ( )
137
- . world_accessible ( true )
138
- . tempfile ( )
139
- . expect ( "Unable to create file" ) ;
137
+ let basic_key_dir = tempfile:: Builder :: new ( )
138
+ . prefix ( "hidio" )
139
+ . tempdir ( )
140
+ . expect ( "Unable to create dir" ) ;
141
+ let mut basic_key_file =
142
+ File :: create ( basic_key_dir. path ( ) . join ( "key" ) ) . expect ( "Unable to create file" ) ;
140
143
141
144
// Create temp file for auth key
142
145
// Only this user can read the auth key
143
146
let mut auth_key_file = tempfile:: Builder :: new ( )
144
- . world_accessible ( false )
145
147
. tempfile ( )
146
148
. expect ( "Unable to create file" ) ;
147
149
@@ -172,7 +174,7 @@ impl HidIoServerImpl {
172
174
basic_key,
173
175
auth_key,
174
176
175
- basic_key_file ,
177
+ basic_key_dir ,
176
178
auth_key_file,
177
179
178
180
subscriptions,
@@ -297,7 +299,7 @@ impl hidio_capnp::hid_io_server::Server for HidIoServerImpl {
297
299
) -> Promise < ( ) , Error > {
298
300
// Get and set fields
299
301
let mut key = results. get ( ) . init_key ( ) ;
300
- key. set_basic_key_path ( & self . basic_key_file . path ( ) . display ( ) . to_string ( ) ) ;
302
+ key. set_basic_key_path ( & self . basic_key_dir . path ( ) . join ( "key" ) . display ( ) . to_string ( ) ) ;
301
303
key. set_auth_key_path ( & self . auth_key_file . path ( ) . display ( ) . to_string ( ) ) ;
302
304
Promise :: ok ( ( ) )
303
305
}
0 commit comments