diff --git a/src/client.rs b/src/client.rs index 648dd26..a54be3f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -49,7 +49,7 @@ use crate::common::NoExtension; use crate::config::EppClientConfig; use crate::error; use crate::hello::{Greeting, GreetingDocument, HelloDocument}; -use crate::registry::{epp_connect, EppConnection}; +use crate::registry::EppConnection; use crate::request::{Command, Extension, Transaction}; use crate::response::Response; use crate::xml::EppXml; @@ -73,10 +73,9 @@ impl EppClient { None => return Err(format!("missing credentials for {}", registry).into()), }; - let stream = epp_connect(registry_creds).await?; - let connection = EppConnection::new(registry.to_string(), stream).await?; - - Ok(EppClient { connection }) + Ok(EppClient { + connection: EppConnection::connect(registry.to_string(), registry_creds).await?, + }) } /// Executes an EPP Hello call and returns the response as an `Greeting` diff --git a/src/registry.rs b/src/registry.rs index 1ad0565..83a8be8 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -26,10 +26,12 @@ pub struct EppConnection { impl EppConnection { /// Create an EppConnection instance with the stream to the registry - pub async fn new( + pub async fn connect( registry: String, - mut stream: TlsStream, + config: &RegistryConfig, ) -> Result> { + let mut stream = epp_connect(config).await?; + let mut buf = vec![0u8; 4096]; stream.read(&mut buf).await?; let greeting = str::from_utf8(&buf[4..])?.to_string(); @@ -118,7 +120,7 @@ impl EppConnection { /// Establishes a TLS connection to a registry and returns a ConnectionStream instance containing the /// socket stream to read/write to the connection -pub async fn epp_connect( +async fn epp_connect( registry_creds: &RegistryConfig, ) -> Result, error::Error> { info!(