cargo clippy --fix

This commit is contained in:
Nicholas Rempel 2021-10-27 15:45:32 -07:00 committed by masalachai
parent ea98b5bd05
commit 4d4da1c52a
17 changed files with 45 additions and 64 deletions

View File

@ -17,11 +17,11 @@ fn element_name_macro(ast: &syn::DeriveInput) -> TokenStream {
let mut elem_name = ast.ident.to_string(); let mut elem_name = ast.ident.to_string();
let (impl_generics, type_generics, _) = &ast.generics.split_for_impl(); let (impl_generics, type_generics, _) = &ast.generics.split_for_impl();
if ast.attrs.len() > 0 { if !ast.attrs.is_empty() {
let attribute = &ast.attrs[0]; let attribute = &ast.attrs[0];
match attribute.parse_meta() { match attribute.parse_meta() {
Ok(syn::Meta::List(meta)) => { Ok(syn::Meta::List(meta)) => {
if meta.nested.len() > 0 { if !meta.nested.is_empty() {
elem_name = match &meta.nested[0] { elem_name = match &meta.nested[0] {
syn::NestedMeta::Meta(syn::Meta::NameValue(v)) => match &v.lit { syn::NestedMeta::Meta(syn::Meta::NameValue(v)) => match &v.lit {
syn::Lit::Str(lit) => lit.value(), syn::Lit::Str(lit) => lit.value(),

View File

@ -137,31 +137,23 @@ impl EppClientConnection {
} }
/// Parses the client certificate chain /// Parses the client certificate chain
fn client_certificate(&self) -> Option<Vec<Certificate>> { fn client_certificate(&self) -> Option<Vec<Certificate>> {
match &self.tls_files { self.tls_files.as_ref().map(|tls| rustls_pemfile::certs(&mut io::BufReader::new(
Some(tls) => Some(
rustls_pemfile::certs(&mut io::BufReader::new(
fs::File::open(tls.cert_chain.to_string()).unwrap(), fs::File::open(tls.cert_chain.to_string()).unwrap(),
)) ))
.unwrap() .unwrap()
.iter() .iter()
.map(|v| Certificate(v.clone())) .map(|v| Certificate(v.clone()))
.collect(), .collect())
),
None => None,
}
} }
/// Parses the client RSA private key /// Parses the client RSA private key
fn key(&self) -> Option<PrivateKey> { fn key(&self) -> Option<PrivateKey> {
match &self.tls_files { self.tls_files.as_ref().map(|tls| rustls::PrivateKey(
Some(tls) => Some(rustls::PrivateKey(
rustls_pemfile::rsa_private_keys(&mut io::BufReader::new( rustls_pemfile::rsa_private_keys(&mut io::BufReader::new(
fs::File::open(tls.key.to_string()).unwrap(), fs::File::open(tls.key.to_string()).unwrap(),
)) ))
.unwrap()[0] .unwrap()[0]
.clone(), .clone(),
)), ))
None => None,
}
} }
} }

View File

@ -50,19 +50,14 @@ async fn connect(registry: &'static str) -> Result<EppClient, Box<dyn Error>> {
let (tx, rx) = mpsc::channel(); let (tx, rx) = mpsc::channel();
tokio::spawn(async move { tokio::spawn(async move {
let stream = epp_connect(&registry_creds).await.unwrap(); let stream = epp_connect(registry_creds).await.unwrap();
let credentials = registry_creds.credentials(); let credentials = registry_creds.credentials();
let ext_uris = registry_creds.ext_uris(); let ext_uris = registry_creds.ext_uris();
let ext_uris = match ext_uris { let ext_uris = ext_uris.map(|uris| uris
Some(uris) => Some(
uris
.iter() .iter()
.map(|u| u.to_string()) .map(|u| u.to_string())
.collect::<Vec<String>>() .collect::<Vec<String>>());
),
None => None,
};
let connection = EppConnection::new( let connection = EppConnection::new(
registry.to_string(), registry.to_string(),
@ -119,9 +114,9 @@ impl EppClient {
/// Makes a login request to the registry and initializes an EppClient instance with it /// Makes a login request to the registry and initializes an EppClient instance with it
async fn build(connection: EppConnection, credentials: (String, String), ext_uris: Option<Vec<String>>) -> Result<EppClient, Box<dyn Error>> { async fn build(connection: EppConnection, credentials: (String, String), ext_uris: Option<Vec<String>>) -> Result<EppClient, Box<dyn Error>> {
let mut client = EppClient { let mut client = EppClient {
connection: connection, connection,
credentials: credentials, credentials,
ext_uris: ext_uris, ext_uris,
// client_tr_id_fn: Arc::new(default_client_tr_id_fn), // client_tr_id_fn: Arc::new(default_client_tr_id_fn),
}; };
@ -164,12 +159,12 @@ impl EppClient {
/// Accepts raw EPP XML and returns the raw EPP XML response to it. /// Accepts raw EPP XML and returns the raw EPP XML response to it.
/// Not recommended for direct use but sometimes can be useful for debugging /// Not recommended for direct use but sometimes can be useful for debugging
pub async fn transact_xml(&mut self, xml: &str) -> Result<String, Box<dyn Error>> { pub async fn transact_xml(&mut self, xml: &str) -> Result<String, Box<dyn Error>> {
self.connection.transact(&xml).await self.connection.transact(xml).await
} }
/// Returns the greeting received on establishment of the connection in raw xml form /// Returns the greeting received on establishment of the connection in raw xml form
pub fn xml_greeting(&self) -> String { pub fn xml_greeting(&self) -> String {
return String::from(&self.connection.greeting) String::from(&self.connection.greeting)
} }
/// Returns the greeting received on establishment of the connection as an `EppGreeting` /// Returns the greeting received on establishment of the connection as an `EppGreeting`

View File

@ -38,9 +38,9 @@ impl EppConnection {
debug!("{}: greeting: {}", registry, greeting); debug!("{}: greeting: {}", registry, greeting);
Ok(EppConnection { Ok(EppConnection {
registry: registry, registry,
stream: stream, stream,
greeting: greeting greeting
}) })
} }
@ -64,7 +64,7 @@ impl EppConnection {
let len_u32: [u8; 4] = u32::to_be_bytes(len.try_into()?); let len_u32: [u8; 4] = u32::to_be_bytes(len.try_into()?);
buf[..4].clone_from_slice(&len_u32); buf[..4].clone_from_slice(&len_u32);
buf[4..].clone_from_slice(&content.as_bytes()); buf[4..].clone_from_slice(content.as_bytes());
self.write(&buf).await self.write(&buf).await
} }
@ -89,7 +89,7 @@ impl EppConnection {
debug!("{}: Read: {} bytes", self.registry, read); debug!("{}: Read: {} bytes", self.registry, read);
buf.extend_from_slice(&read_buf[0..read]); buf.extend_from_slice(&read_buf[0..read]);
read_size = read_size + read; read_size += read;
debug!("{}: Total read: {} bytes", self.registry, read_size); debug!("{}: Total read: {} bytes", self.registry, read_size);
if read == 0 { if read == 0 {
@ -117,7 +117,7 @@ impl EppConnection {
/// receieved to the request /// receieved to the request
pub async fn transact(&mut self, content: &str) -> Result<String, Box<dyn Error>> { pub async fn transact(&mut self, content: &str) -> Result<String, Box<dyn Error>> {
debug!("{}: request: {}", self.registry, content); debug!("{}: request: {}", self.registry, content);
self.send_epp_request(&content).await?; self.send_epp_request(content).await?;
let response = self.get_epp_response().await?; let response = self.get_epp_response().await?;
debug!("{}: response: {}", self.registry, response); debug!("{}: response: {}", self.registry, response);
@ -149,8 +149,7 @@ pub async fn epp_connect(registry_creds: &EppClientConnection) -> Result<Connect
let addr = (host.as_str(), port) let addr = (host.as_str(), port)
.to_socket_addrs()? .to_socket_addrs()?
.next() .next().ok_or(stdio::ErrorKind::NotFound)?;
.ok_or_else(|| stdio::ErrorKind::NotFound)?;
let mut roots = RootCertStore::empty(); let mut roots = RootCertStore::empty();
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| { roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
@ -184,7 +183,7 @@ pub async fn epp_connect(registry_creds: &EppClientConnection) -> Result<Connect
let (reader, writer) = split(stream); let (reader, writer) = split(stream);
Ok(ConnectionStream { Ok(ConnectionStream {
reader: reader, reader,
writer: writer, writer,
}) })
} }

View File

@ -156,7 +156,7 @@ impl<T: ElementName> EppObject<T> {
pub fn build(data: T) -> EppObject<T> { pub fn build(data: T) -> EppObject<T> {
EppObject { EppObject {
// xml: None, // xml: None,
data: data, data,
xmlns: EPP_XMLNS.to_string(), xmlns: EPP_XMLNS.to_string(),
xmlns_xsi: EPP_XMLNS_XSI.to_string(), xmlns_xsi: EPP_XMLNS_XSI.to_string(),
xsi_schema_location: EPP_XSI_SCHEMA_LOCATION.to_string(), xsi_schema_location: EPP_XSI_SCHEMA_LOCATION.to_string(),

View File

@ -106,7 +106,7 @@ impl Period {
pub fn new(length: u16) -> Period { pub fn new(length: u16) -> Period {
Period { Period {
unit: "y".to_string(), unit: "y".to_string(),
length: length, length,
} }
} }
@ -216,7 +216,7 @@ impl Address {
.collect::<Vec<StringValue>>(); .collect::<Vec<StringValue>>();
Address { Address {
street: street, street,
city: city.to_string_value(), city: city.to_string_value(),
province: province.to_string_value(), province: province.to_string_value(),
postal_code: postal_code.to_string_value(), postal_code: postal_code.to_string_value(),
@ -232,7 +232,7 @@ impl PostalInfo {
info_type: info_type.to_string(), info_type: info_type.to_string(),
name: name.to_string_value(), name: name.to_string_value(),
organization: organization.to_string_value(), organization: organization.to_string_value(),
address: address, address,
} }
} }
} }

View File

@ -61,7 +61,7 @@ impl<T: ElementName> Command<T> {
/// Creates a new &lt;command&gt; tag for an EPP document /// Creates a new &lt;command&gt; tag for an EPP document
pub fn new(command: T, client_tr_id: &str) -> Command<T> { pub fn new(command: T, client_tr_id: &str) -> Command<T> {
Command { Command {
command: command, command,
extension: None, extension: None,
client_tr_id: client_tr_id.to_string_value(), client_tr_id: client_tr_id.to_string_value(),
} }
@ -72,7 +72,7 @@ impl<T: ElementName, E: ElementName> CommandWithExtension<T, E> {
/// Creates a new &lt;command&gt; tag for an EPP document with a containing &lt;extension&gt; tag /// Creates a new &lt;command&gt; tag for an EPP document with a containing &lt;extension&gt; tag
pub fn build(command: T, ext: E, client_tr_id: &str) -> CommandWithExtension<T, E> { pub fn build(command: T, ext: E, client_tr_id: &str) -> CommandWithExtension<T, E> {
CommandWithExtension { CommandWithExtension {
command: command, command,
extension: Some(Extension { data: ext }), extension: Some(Extension { data: ext }),
client_tr_id: client_tr_id.to_string_value(), client_tr_id: client_tr_id.to_string_value(),
} }
@ -122,14 +122,9 @@ impl EppLogin {
ext_uris: &Option<Vec<String>>, ext_uris: &Option<Vec<String>>,
client_tr_id: &str, client_tr_id: &str,
) -> EppLogin { ) -> EppLogin {
let ext_uris = match ext_uris { let ext_uris = ext_uris.as_ref().map(|uris| uris.iter()
Some(uris) => Some(
uris.iter()
.map(|u| u.to_string_value()) .map(|u| u.to_string_value())
.collect::<Vec<StringValue>>(), .collect::<Vec<StringValue>>());
),
None => None,
};
let login = Login { let login = Login {
username: username.to_string_value(), username: username.to_string_value(),
@ -144,7 +139,7 @@ impl EppLogin {
EPP_CONTACT_XMLNS.to_string_value(), EPP_CONTACT_XMLNS.to_string_value(),
EPP_DOMAIN_XMLNS.to_string_value(), EPP_DOMAIN_XMLNS.to_string_value(),
], ],
svc_ext: Some(ServiceExtension { ext_uris: ext_uris }), svc_ext: Some(ServiceExtension { ext_uris }),
}, },
}; };

View File

@ -69,7 +69,7 @@ impl EppContactCheck {
let contact_check = ContactCheck { let contact_check = ContactCheck {
list: ContactList { list: ContactList {
xmlns: EPP_CONTACT_XMLNS.to_string(), xmlns: EPP_CONTACT_XMLNS.to_string(),
contact_ids: contact_ids, contact_ids,
}, },
}; };

View File

@ -99,8 +99,8 @@ impl EppContactCreate {
contact: Contact { contact: Contact {
xmlns: EPP_CONTACT_XMLNS.to_string(), xmlns: EPP_CONTACT_XMLNS.to_string(),
id: id.to_string_value(), id: id.to_string_value(),
postal_info: postal_info, postal_info,
voice: voice, voice,
fax: None, fax: None,
email: email.to_string_value(), email: email.to_string_value(),
auth_info: data::AuthInfo::new(auth_password), auth_info: data::AuthInfo::new(auth_password),

View File

@ -151,7 +151,7 @@ impl EppContactUpdate {
email: Some(res_data.info_data.email.clone()), email: Some(res_data.info_data.email.clone()),
postal_info: Some(res_data.info_data.postal_info.clone()), postal_info: Some(res_data.info_data.postal_info.clone()),
voice: Some(res_data.info_data.voice.clone()), voice: Some(res_data.info_data.voice.clone()),
fax: res_data.info_data.fax.clone(), fax: res_data.info_data.fax,
auth_info: None, auth_info: None,
}); });
Ok(()) Ok(())

View File

@ -69,7 +69,7 @@ impl EppDomainCheck {
let domain_check = DomainCheck { let domain_check = DomainCheck {
list: DomainList { list: DomainList {
xmlns: EPP_DOMAIN_XMLNS.to_string(), xmlns: EPP_DOMAIN_XMLNS.to_string(),
domains: domains, domains,
}, },
}; };

View File

@ -161,7 +161,7 @@ impl EppDomainRgpRestoreReport {
.to_rfc3339_opts(SecondsFormat::AutoSi, true) .to_rfc3339_opts(SecondsFormat::AutoSi, true)
.to_string_value(), .to_string_value(),
restore_reason: restore_reason.to_string_value(), restore_reason: restore_reason.to_string_value(),
statements: statements, statements,
other: other.to_string_value(), other: other.to_string_value(),
}, },
}, },

View File

@ -69,7 +69,7 @@ impl EppHostCheck {
let host_check = HostCheck { let host_check = HostCheck {
list: HostList { list: HostList {
xmlns: EPP_HOST_XMLNS.to_string(), xmlns: EPP_HOST_XMLNS.to_string(),
hosts: hosts, hosts,
}, },
}; };

View File

@ -261,14 +261,14 @@ impl<T, E: ElementName> CommandResponseWithExtension<T, E> {
/// Returns the data under the corresponding &lt;resData&gt; from the EPP XML /// Returns the data under the corresponding &lt;resData&gt; from the EPP XML
pub fn res_data(&self) -> Option<&T> { pub fn res_data(&self) -> Option<&T> {
match &self.res_data { match &self.res_data {
Some(res_data) => Some(&res_data), Some(res_data) => Some(res_data),
None => None, None => None,
} }
} }
/// Returns the data under the corresponding <msgQ> from the EPP XML /// Returns the data under the corresponding <msgQ> from the EPP XML
pub fn message_queue(&self) -> Option<&MessageQueue> { pub fn message_queue(&self) -> Option<&MessageQueue> {
match &self.message_queue { match &self.message_queue {
Some(queue) => Some(&queue), Some(queue) => Some(queue),
None => None, None => None,
} }
} }

View File

@ -25,7 +25,7 @@ impl<T: Serialize + DeserializeOwned + ElementName + Debug> EppXml for EppObject
Ok(v) => v, Ok(v) => v,
Err(e) => { Err(e) => {
return Err(error::Error::EppDeserializationError( return Err(error::Error::EppDeserializationError(
format!("epp-client Deserialization Error: {}", e).to_string(), format!("epp-client Deserialization Error: {}", e),
)) ))
} }
}; };

View File

@ -34,7 +34,7 @@ impl Display for Error {
impl From<std::boxed::Box<dyn std::error::Error>> for Error { impl From<std::boxed::Box<dyn std::error::Error>> for Error {
fn from(e: std::boxed::Box<dyn std::error::Error>) -> Self { fn from(e: std::boxed::Box<dyn std::error::Error>) -> Self {
Self::Other(format!("{:?}", e).to_string()) Self::Other(format!("{:?}", e))
} }
} }

View File

@ -17,8 +17,8 @@ fn get_xml(path: &str) -> Result<String, Box<dyn Error>> {
let mut buf = String::new(); let mut buf = String::new();
f.read_to_string(&mut buf)?; f.read_to_string(&mut buf)?;
if buf.len() > 0 { if !buf.is_empty() {
let mat = Regex::new(r"\?>").unwrap().find(&buf.as_str()).unwrap(); let mat = Regex::new(r"\?>").unwrap().find(buf.as_str()).unwrap();
let start = mat.end(); let start = mat.end();
buf = format!( buf = format!(
"{}\r\n{}", "{}\r\n{}",