Skip to content

Commit a96bb13

Browse files
authored
Merge pull request RustCrypto#29 from wiktor-k/use-bind
Rename `NamedPipeListener::new` to `bind` for consistency
2 parents 691f431 + 6f147ae commit a96bb13

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

ssh-agent-lib/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ On Unix it uses `ssh-agent.sock` Unix domain socket while on Windows it uses a n
1414

1515
```rust,no_run
1616
#[cfg(not(windows))]
17-
use tokio::net::UnixListener;
17+
use tokio::net::UnixListener as Listener;
1818
#[cfg(windows)]
19-
use ssh_agent_lib::agent::NamedPipeListener;
19+
use ssh_agent_lib::agent::NamedPipeListener as Listener;
2020
2121
use ssh_agent_lib::agent::{Session, Agent};
2222
use ssh_agent_lib::proto::message::Message;
@@ -43,19 +43,15 @@ impl Session for MyAgent {
4343
}
4444
4545
#[tokio::main]
46-
#[cfg(not(windows))]
4746
async fn main() -> Result<(), Box<dyn std::error::Error>> {
47+
#[cfg(not(windows))]
4848
let socket = "ssh-agent.sock";
49-
let _ = std::fs::remove_file(socket); // remove the socket if exists
49+
#[cfg(windows)]
50+
let socket = r"\\.\pipe\agent";
5051
51-
MyAgent.listen(UnixListener::bind(socket)?).await?;
52-
Ok(())
53-
}
52+
let _ = std::fs::remove_file(socket); // remove the socket if exists
5453
55-
#[tokio::main]
56-
#[cfg(windows)]
57-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
58-
MyAgent.listen(NamedPipeListener::new(r"\\.\pipe\agent".into())?).await?;
54+
MyAgent.listen(Listener::bind(socket)?).await?;
5955
Ok(())
6056
}
6157
```

ssh-agent-lib/examples/key_storage.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use async_trait::async_trait;
22
use log::info;
33
#[cfg(windows)]
4-
use ssh_agent_lib::agent::NamedPipeListener;
4+
use ssh_agent_lib::agent::NamedPipeListener as Listener;
55
use ssh_agent_lib::proto::extension::SessionBind;
66
#[cfg(not(windows))]
7-
use tokio::net::UnixListener;
7+
use tokio::net::UnixListener as Listener;
88

99
use ssh_agent_lib::agent::{Agent, Session};
1010
use ssh_agent_lib::proto::message::{self, Message, SignRequest};
@@ -221,26 +221,22 @@ impl Agent for KeyStorageAgent {
221221
}
222222

223223
#[tokio::main]
224-
#[cfg(not(windows))]
225224
async fn main() -> Result<(), Box<dyn std::error::Error>> {
226225
env_logger::init();
226+
227+
#[cfg(not(windows))]
227228
let socket = "ssh-agent.sock";
228-
let _ = std::fs::remove_file(socket); // remove the socket if exists
229+
#[cfg(windows)]
230+
let socket = r"\\.\pipe\agent";
229231

230-
KeyStorageAgent::new()
231-
.listen(UnixListener::bind(socket)?)
232-
.await?;
233-
Ok(())
234-
}
232+
let _ = std::fs::remove_file(socket); // remove the socket if exists
235233

236-
#[tokio::main]
237-
#[cfg(windows)]
238-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
239234
// This is only used for integration tests on Windows:
235+
#[cfg(windows)]
240236
std::fs::File::create("server-started")?;
241-
// ^ You can remove this line
237+
242238
KeyStorageAgent::new()
243-
.listen(NamedPipeListener::new(r"\\.\pipe\agent".into())?)
239+
.listen(Listener::bind(socket)?)
244240
.await?;
245241
Ok(())
246242
}

ssh-agent-lib/src/agent.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ pub struct NamedPipeListener(NamedPipeServer, std::ffi::OsString);
9292

9393
#[cfg(windows)]
9494
impl NamedPipeListener {
95-
pub fn new(pipe: std::ffi::OsString) -> std::io::Result<Self> {
95+
pub fn bind(pipe: impl Into<std::ffi::OsString>) -> std::io::Result<Self> {
96+
let pipe = pipe.into();
9697
Ok(NamedPipeListener(
9798
ServerOptions::new()
9899
.first_pipe_instance(true)
@@ -185,7 +186,7 @@ pub trait Agent: 'static + Sync + Send + Sized {
185186
}
186187
#[cfg(windows)]
187188
service_binding::Listener::NamedPipe(pipe) => {
188-
self.listen(NamedPipeListener::new(pipe)?).await
189+
self.listen(NamedPipeListener::bind(pipe)?).await
189190
}
190191
#[cfg(not(windows))]
191192
service_binding::Listener::NamedPipe(_) => Err(AgentError::IO(std::io::Error::other(

0 commit comments

Comments
 (0)