style: cargo clippy --fix

This commit is contained in:
DarkCat09 2024-08-06 20:27:12 +04:00
parent e93a177b25
commit 96a6ad34a0
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
7 changed files with 28 additions and 22 deletions

View file

@ -182,8 +182,8 @@ impl SelfsignedCertVerifier for CertVerifier {
);
f.write_all(host.as_bytes())?;
f.write_all(b" 0 sha512 ")?; // TODO after implementing `expires`
f.write_all(&this_fp.as_bytes())?;
f.write(b"\n")?;
f.write_all(this_fp.as_bytes())?;
f.write_all(b"\n")?;
Ok::<(), std::io::Error>(())
})()
.unwrap_or_else(|e| {

View file

@ -19,6 +19,12 @@ pub struct ClientBuilder {
tls_versions: Option<&'static [&'static SupportedProtocolVersion]>,
}
impl Default for ClientBuilder {
fn default() -> Self {
Self::new()
}
}
impl ClientBuilder {
pub fn new() -> Self {
ClientBuilder {
@ -31,7 +37,7 @@ impl ClientBuilder {
pub fn build(self) -> Client {
let provider = rustls::crypto::CryptoProvider::get_default()
.map(|c| c.clone())
.cloned()
.unwrap_or_else(|| Arc::new(rustls::crypto::ring::default_provider()));
let tls_config = rustls::ClientConfig::builder_with_provider(provider.clone())

View file

@ -11,7 +11,7 @@ impl AllowAllCertVerifier {
pub fn yes_i_know_what_i_am_doing() -> Self {
AllowAllCertVerifier(
CryptoProvider::get_default()
.map(|c| c.clone())
.cloned()
.unwrap_or_else(|| std::sync::Arc::new(rustls::crypto::ring::default_provider())),
)
}

View file

@ -68,7 +68,7 @@ impl ServerCertVerifier for CustomCertVerifier {
// (probably with rustls-webpki's webpki::Cert)
if self
.ss_verifier
.verify(end_entity, &server_name.to_str().as_ref(), now)?
.verify(end_entity, server_name.to_str().as_ref(), now)?
{
return Ok(ServerCertVerified::assertion());
}

View file

@ -44,8 +44,8 @@ impl Client {
}
impl Client {
pub async fn request(self: &Self, url_str: &str) -> Result<Response, LibError> {
let url = Url::parse(url_str).map_err(|e| InvalidUrl::ParseError(e))?;
pub async fn request(&self, url_str: &str) -> Result<Response, LibError> {
let url = Url::parse(url_str).map_err(InvalidUrl::ParseError)?;
// for proxying http(s) through gemini server,
// use Client::request_with_host
if url.scheme() != "gemini" {
@ -64,7 +64,7 @@ impl Client {
}
pub async fn request_with_host(
self: &Self,
&self,
url_str: &str,
host: &str,
port: u16,
@ -111,7 +111,7 @@ impl Client {
// ...otherwise, CR is a part of message, not a CRLF terminator,
// so append that one byte that's supposed to be LF (but not LF)
// to the message buffer
result.push(buf[0].into());
result.push(buf[0]);
}
}

View file

@ -22,11 +22,11 @@ impl Response {
}
#[inline]
pub fn is_ok(self: &Self) -> bool {
pub fn is_ok(&self) -> bool {
self.status.reply_type() == ReplyType::Success
}
pub fn ensure_ok(self: Self) -> Result<Self, Self> {
pub fn ensure_ok(self) -> Result<Self, Self> {
if self.status.reply_type() == ReplyType::Success {
Ok(self)
} else {
@ -34,29 +34,29 @@ impl Response {
}
}
pub fn status(self: &Self) -> Status {
pub fn status(&self) -> Status {
self.status
}
pub fn message(self: &Self) -> &str {
pub fn message(&self) -> &str {
&self.message
}
pub fn mime(self: &Self) -> Result<mime::Mime, LibError> {
self.message.parse().map_err(|e| LibError::InvalidMime(e))
pub fn mime(&self) -> Result<mime::Mime, LibError> {
self.message.parse().map_err(LibError::InvalidMime)
}
pub fn stream(self: &mut Self) -> &mut BodyStream {
pub fn stream(&mut self) -> &mut BodyStream {
&mut self.stream
}
pub async fn bytes(self: &mut Self) -> Result<Bytes, LibError> {
pub async fn bytes(&mut self) -> Result<Bytes, LibError> {
let mut buf = Vec::new();
self.stream.read_to_end(&mut buf).await?;
Ok(Bytes::from(buf))
}
pub async fn text(self: &mut Self) -> Result<String, LibError> {
pub async fn text(&mut self) -> Result<String, LibError> {
let mut buf = String::new();
self.stream.read_to_string(&mut buf).await?;
Ok(buf)

View file

@ -77,19 +77,19 @@ impl Status {
})
}
pub fn status_code(self: &Self) -> StatusCode {
pub fn status_code(&self) -> StatusCode {
self.status_code
}
pub fn num(self: &Self) -> u8 {
pub fn num(&self) -> u8 {
self.status_code.into()
}
pub fn reply_type(self: &Self) -> ReplyType {
pub fn reply_type(&self) -> ReplyType {
self.reply_type
}
pub fn second_digit(self: &Self) -> u8 {
pub fn second_digit(&self) -> u8 {
self.second_digit
}
}