summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-02-18 11:14:58 +0100
committerNora Widdecke <nora@sequoia-pgp.org>2022-02-25 10:23:34 +0100
commit421f8a0908bb118ce21061cbb3fb11df94143e3b (patch)
tree6b24a72b5106e9601fb170962e26c578a96f051e /src
parent8eb3984560240981e44a630c950935cd4ccf1c66 (diff)
lint: Apply clippy autofixes
clippy::needless_borrow clippy::single_char_pattern clippy::redundant_clone clippy::needless_return clippy::needless_question_mark clippy::useless_conversion clippy::to_string_in_format_args clippy::to_string_in_format_args clippy::useless_format clippy::useless_vec clippy::toplevel_ref_arg clippy::redundant_static_lifetimes clippy::try_err
Diffstat (limited to 'src')
-rw-r--r--src/delete.rs2
-rw-r--r--src/dump.rs2
-rw-r--r--src/i18n.rs6
-rw-r--r--src/mail.rs6
-rw-r--r--src/sealed_state.rs2
-rw-r--r--src/tokens.rs2
-rw-r--r--src/web/hkp.rs14
-rw-r--r--src/web/mod.rs87
-rw-r--r--src/web/vks.rs14
-rw-r--r--src/web/vks_api.rs2
-rw-r--r--src/web/vks_web.rs22
11 files changed, 79 insertions, 80 deletions
diff --git a/src/delete.rs b/src/delete.rs
index 3da0e7d..d06d875 100644
--- a/src/delete.rs
+++ b/src/delete.rs
@@ -65,7 +65,7 @@ fn delete(db: &KeyDatabase, query: &Query, all_bindings: bool, mut all: bool)
_ => (),
}
- let tpk = db.lookup(&query)?.ok_or_else(
+ let tpk = db.lookup(query)?.ok_or_else(
|| anyhow::format_err!("No TPK matching {:?}", query))?;
let fp: database::types::Fingerprint = tpk.fingerprint().try_into()?;
diff --git a/src/dump.rs b/src/dump.rs
index bdb7a45..5ed0168 100644
--- a/src/dump.rs
+++ b/src/dump.rs
@@ -238,7 +238,7 @@ impl PacketDumper {
pub fn flush(&self, output: &mut dyn io::Write) -> Result<()> {
if let Some(root) = self.root.as_ref() {
- self.dump_tree(output, "", &root)?;
+ self.dump_tree(output, "", root)?;
}
Ok(())
}
diff --git a/src/i18n.rs b/src/i18n.rs
index 996cbd7..903b0d0 100644
--- a/src/i18n.rs
+++ b/src/i18n.rs
@@ -93,14 +93,14 @@ impl HelperDef for I18NHelper {
{
RenderError::from_error("Failed to render", e)
}
- let response = self.lookup(lang, &id);
+ let response = self.lookup(lang, id);
if rerender {
let data = rcx.evaluate(context, "this").unwrap();
- let response = reg.render_template(&response, data.as_json())
+ let response = reg.render_template(response, data.as_json())
.map_err(render_error_with)?;
out.write(&response).map_err(render_error_with)?;
} else {
- out.write(&response).map_err(render_error_with)?;
+ out.write(response).map_err(render_error_with)?;
}
Ok(())
}
diff --git a/src/mail.rs b/src/mail.rs
index 654cd09..828fb38 100644
--- a/src/mail.rs
+++ b/src/mail.rs
@@ -102,7 +102,7 @@ impl Service {
counters::inc_mail_sent("verify", userid);
self.send(
- &vec![userid],
+ &[userid],
&i18n!(
i18n.catalog,
context = "Subject for verification email, {0} = userid, {1} = keyserver domain",
@@ -166,7 +166,7 @@ impl Service {
counters::inc_mail_sent("welcome", userid);
self.send(
- &vec![userid],
+ &[userid],
&format!("Your key upload on {domain}", domain = self.domain),
"welcome",
"en",
@@ -202,7 +202,7 @@ impl Service {
if cfg!(debug_assertions) {
for recipient in to.iter() {
- println!("To: {}", recipient.to_string());
+ println!("To: {}", recipient);
}
println!("{}", &txt);
}
diff --git a/src/sealed_state.rs b/src/sealed_state.rs
index 4bbd66e..b794666 100644
--- a/src/sealed_state.rs
+++ b/src/sealed_state.rs
@@ -6,7 +6,7 @@ use ring::digest;
// Keep these in sync, and keep the key len synced with the `private` docs as
// well as the `KEYS_INFO` const in secure::Key.
-static ALGO: &'static Algorithm = &AES_256_GCM;
+static ALGO: &Algorithm = &AES_256_GCM;
const NONCE_LEN: usize = 12;
pub struct SealedState {
diff --git a/src/tokens.rs b/src/tokens.rs
index a9f6d23..e43ca0a 100644
--- a/src/tokens.rs
+++ b/src/tokens.rs
@@ -48,7 +48,7 @@ impl Service {
let elapsed = current_time() - token.creation;
if elapsed > self.validity {
- Err(anyhow!("Token has expired!"))?;
+ return Err(anyhow!("Token has expired!"));
}
let payload: T = serde_json::from_str(&token.payload)
diff --git a/src/web/hkp.rs b/src/web/hkp.rs
index 547e35f..d1bf80f 100644
--- a/src/web/hkp.rs
+++ b/src/web/hkp.rs
@@ -75,7 +75,7 @@ impl<'r> FromRequest<'r> for Hkp {
(search.starts_with("0x") && search.len() < 16 || search.len() == 8);
if looks_like_short_key_id {
Outcome::Success(Hkp::ShortKeyID {
- query: search.to_string(),
+ query: search,
index,
})
} else if let Ok(fpr) = maybe_fpr {
@@ -141,9 +141,9 @@ pub async fn pks_add_form(
i18n: I18n,
data: Data<'_>,
) -> MyResponse {
- match vks_web::process_post_form(&db, &tokens_stateless, &rate_limiter, &i18n, data).await {
+ match vks_web::process_post_form(db, tokens_stateless, rate_limiter, &i18n, data).await {
Ok(UploadResponse::Ok { is_new_key, key_fpr, primary_uid, token, status, .. }) => {
- let msg = pks_add_ok(&origin, &mail_service, &rate_limiter, token, status, is_new_key, key_fpr, primary_uid);
+ let msg = pks_add_ok(&origin, mail_service, rate_limiter, token, status, is_new_key, key_fpr, primary_uid);
MyResponse::plain(msg)
}
Ok(_) => {
@@ -170,16 +170,16 @@ fn pks_add_ok(
let primary_uid = primary_uid.unwrap();
if is_new_key {
- if send_welcome_mail(&origin, &mail_service, key_fpr, &primary_uid, token) {
+ if send_welcome_mail(origin, mail_service, key_fpr, &primary_uid, token) {
rate_limiter.action_perform(format!("hkp-sent-{}", &primary_uid));
- return format!("Upload successful. This is a new key, a welcome email has been sent.");
+ return "Upload successful. This is a new key, a welcome email has been sent.".to_string();
}
return format!("Upload successful. Please note that identity information will only be published after verification. See {baseuri}/about/usage#gnupg-upload", baseuri = origin.get_base_uri())
}
let has_unverified = status.iter().any(|(_, v)| *v == EmailStatus::Unpublished);
if !has_unverified {
- return format!("Upload successful.");
+ return "Upload successful.".to_string();
}
return format!("Upload successful. Please note that identity information will only be published after verification. See {baseuri}/about/usage#gnupg-upload", baseuri = origin.get_base_uri())
@@ -252,7 +252,7 @@ fn key_to_hkp_index(
let mut out = String::default();
let p = tpk.primary_key();
- let ref policy = StandardPolicy::new();
+ let policy = &StandardPolicy::new();
let ctime = format!("{}", p.creation_time().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
let is_rev =
diff --git a/src/web/mod.rs b/src/web/mod.rs
index 0694b0f..02df9c9 100644
--- a/src/web/mod.rs
+++ b/src/web/mod.rs
@@ -263,8 +263,8 @@ pub fn key_to_response_plain(
return MyResponse::not_found_plain(describe_query_error(&i18n, &query));
};
- return match db.by_fpr(&fp) {
- Some(armored) => MyResponse::key(armored, &fp.into()),
+ match db.by_fpr(&fp) {
+ Some(armored) => MyResponse::key(armored, &fp),
None => MyResponse::not_found_plain(describe_query_error(&i18n, &query)),
}
}
@@ -339,7 +339,7 @@ fn errors(
}
pub fn serve() -> Result<rocket::Rocket<rocket::Build>> {
- Ok(rocket_factory(rocket::build())?)
+ rocket_factory(rocket::build())
}
compile_i18n!();
@@ -439,8 +439,8 @@ fn configure_prometheus(config: &Figment) -> Option<PrometheusMetrics> {
return None;
}
let prometheus = PrometheusMetrics::new();
- counters::register_counters(&prometheus.registry());
- return Some(prometheus);
+ counters::register_counters(prometheus.registry());
+ Some(prometheus)
}
fn configure_db_service(config: &Figment) -> Result<KeyDatabase> {
@@ -458,7 +458,6 @@ fn configure_hagrid_state(config: &Figment) -> Result<HagridState> {
// State
let base_uri: String = config.extract_inner("base-URI")?;
let base_uri_onion = config.extract_inner::<String>("base-URI-Onion")
- .map(|c| c.to_string())
.unwrap_or(base_uri.clone());
Ok(HagridState {
assets_dir,
@@ -538,8 +537,8 @@ pub mod tests {
use super::*;
/// Fake base URI to use in tests.
- const BASE_URI: &'static str = "http://local.connection";
- const BASE_URI_ONION: &'static str = "http://local.connection.onion";
+ const BASE_URI: &str = "http://local.connection";
+ const BASE_URI_ONION: &str = "http://local.connection.onion";
pub fn build_cert(name: &str) -> Cert {
let (tpk, _) = CertBuilder::new()
@@ -548,7 +547,7 @@ pub mod tests {
.add_userid(name)
.generate()
.unwrap();
- return tpk;
+ tpk
}
/// Creates a configuration and empty state dir for testing purposes.
@@ -951,11 +950,11 @@ pub mod tests {
/// Asserts that lookups by the given email 404.
pub fn check_null_responses_by_email(client: &Client, addr: &str) {
check_null_response(
- &client, &format!("/vks/v1/by-email/{}", addr));
+ client, &format!("/vks/v1/by-email/{}", addr));
check_null_response(
- &client, &format!("/pks/lookup?op=get&search={}", addr));
+ client, &format!("/pks/lookup?op=get&search={}", addr));
check_null_response(
- &client, &format!("/pks/lookup?op=get&options=mr&search={}",
+ client, &format!("/pks/lookup?op=get&options=mr&search={}",
addr));
}
@@ -963,25 +962,25 @@ pub mod tests {
pub fn check_responses_by_email(client: &Client, addr: &str, tpk: &Cert,
nr_uids: usize) {
check_mr_response(
- &client,
+ client,
&format!("/vks/v1/by-email/{}", addr),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/vks/v1/by-email/{}", addr.replace("@", "%40")),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&options=mr&search={}", addr),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_hr_response(
- &client,
+ client,
&format!("/search?q={}", addr),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_hr_response_onion(
- &client,
+ client,
&format!("/search?q={}", addr),
- &tpk, nr_uids);
+ tpk, nr_uids);
}
/// Asserts that the given URI returns a Cert matching the given
@@ -1030,34 +1029,34 @@ pub mod tests {
let keyid = sequoia_openpgp::KeyID::from(tpk.fingerprint()).to_hex();
check_mr_response(
- &client, &format!("/vks/v1/by-keyid/{}", keyid), &tpk, nr_uids);
+ client, &format!("/vks/v1/by-keyid/{}", keyid), tpk, nr_uids);
check_mr_response(
- &client, &format!("/vks/v1/by-fingerprint/{}", fp), &tpk, nr_uids);
+ client, &format!("/vks/v1/by-fingerprint/{}", fp), tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&options=mr&search={}", fp),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&options=mr&search=0x{}", fp),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&options=mr&search={}", keyid),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&options=mr&search=0x{}", keyid),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_mr_response(
- &client,
+ client,
&format!("/pks/lookup?op=get&search=0x{}", keyid),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_index_response(
- &client,
+ client,
&format!("/pks/lookup?op=index&search={}", fp),
- &tpk);
+ tpk);
}
/// Asserts that the given URI contains the search string.
@@ -1120,21 +1119,21 @@ pub mod tests {
let keyid = sequoia_openpgp::KeyID::from(tpk.fingerprint()).to_hex();
check_hr_response(
- &client,
+ client,
&format!("/search?q={}", fp),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_hr_response(
- &client,
+ client,
&format!("/search?q=0x{}", fp),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_hr_response(
- &client,
+ client,
&format!("/search?q={}", keyid),
- &tpk, nr_uids);
+ tpk, nr_uids);
check_hr_response(
- &client,
+ client,
&format!("/search?q=0x{}", keyid),
- &tpk, nr_uids);
+ tpk, nr_uids);
}
fn check_verify_link(client: &Client, token: &str, address: &str, lang: &'static str) {
diff --git a/src/web/vks.rs b/src/web/vks.rs
index 72b68f5..3e09762 100644
--- a/src/web/vks.rs
+++ b/src/web/vks.rs
@@ -182,7 +182,7 @@ fn process_key_single(
.map(|(email,_)| email.clone())
.collect();
VerifyTpkState {
- fpr: fp.clone(),
+ fpr: fp,
addresses: emails,
requested: vec!(),
}
@@ -204,14 +204,14 @@ pub fn request_verify(
token: String,
addresses: Vec<String>,
) -> response::UploadResponse {
- let (verify_state, tpk_status) = match check_tpk_state(&db, &token_stateless, i18n, &token) {
+ let (verify_state, tpk_status) = match check_tpk_state(db, token_stateless, i18n, &token) {
Ok(ok) => ok,
Err(e) => return UploadResponse::err(&e.to_string()),
};
if tpk_status.is_revoked {
return show_upload_verify(
- &rate_limiter, token, tpk_status, verify_state, false);
+ rate_limiter, token, tpk_status, verify_state, false);
}
let emails_requested: Vec<_> = addresses.into_iter()
@@ -227,13 +227,13 @@ pub fn request_verify(
for email in emails_requested {
let rate_limit_ok = rate_limiter.action_perform(format!("verify-{}", &email));
if rate_limit_ok {
- if send_verify_email(origin, &mail_service, &token_stateful, i18n, &verify_state.fpr, &email).is_err() {
+ if send_verify_email(origin, mail_service, token_stateful, i18n, &verify_state.fpr, &email).is_err() {
return UploadResponse::err(&format!("error sending email to {}", &email));
}
}
}
- show_upload_verify(&rate_limiter, token, tpk_status, verify_state, false)
+ show_upload_verify(rate_limiter, token, tpk_status, verify_state, false)
}
fn check_tpk_state(
@@ -267,7 +267,7 @@ fn send_verify_email(
i18n,
origin.get_base_uri(),
fpr.to_string(),
- &email,
+ email,
&token_verify,
)
}
@@ -278,7 +278,7 @@ pub fn verify_confirm(
token_service: &rocket::State<StatefulTokens>,
token: String,
) -> response::PublishResponse {
- let (fingerprint, email) = match check_publish_token(&db, &token_service, token) {
+ let (fingerprint, email) = match check_publish_token(db, token_service, token) {
Ok(x) => x,
Err(_) => return PublishResponse::err(
i18n!(i18n.catalog, "Invalid verification link.")),
diff --git a/src/web/vks_api.rs b/src/web/vks_api.rs
index 7b78c91..5fbed6a 100644
--- a/src/web/vks_api.rs
+++ b/src/web/vks_api.rs
@@ -86,7 +86,7 @@ pub fn upload_json(
let data = json_or_error(data)?;
use std::io::Cursor;
let data_reader = Cursor::new(data.keytext.as_bytes());
- let result = vks::process_key(&db, &i18n, &tokens_stateless, &rate_limiter, data_reader);
+ let result = vks::process_key(db, &i18n, tokens_stateless, rate_limiter, data_reader);
upload_ok_json(result)
}
diff --git a/src/web/vks_web.rs b/src/web/vks_web.rs
index 6f777ab..24bf34b 100644
--- a/src/web/vks_web.rs
+++ b/src/web/vks_web.rs
@@ -151,7 +151,7 @@ impl MyResponse {
*status == EmailStatus::Pending)
.map(|(email,status)|
template::UploadUidStatus {
- address: email.to_string(),
+ address: email,
requested: status == EmailStatus::Pending,
})
.collect();
@@ -179,7 +179,7 @@ impl MyResponse {
.map(|fpr| {
let key_link = uri!(search(q = &fpr)).to_string();
template::UploadOkKey {
- key_fpr: fpr.to_owned(),
+ key_fpr: fpr,
key_link,
}
})
@@ -224,7 +224,7 @@ pub async fn process_post_form_data(
cont_type: &ContentType,
data: Data<'_>,
) -> Result<UploadResponse> {
- process_upload(&db, &tokens_stateless, &rate_limiter, &i18n, data, cont_type)
+ process_upload(db, tokens_stateless, rate_limiter, &i18n, data, cont_type)
.await
}
@@ -285,10 +285,10 @@ pub async fn quick_upload(
MyResponse::upload_response_quick(
vks::process_key(
- &db,
+ db,
&i18n,
- &tokens_stateless,
- &rate_limiter,
+ tokens_stateless,
+ rate_limiter,
Cursor::new(buf)
),
i18n, origin)
@@ -321,7 +321,7 @@ pub async fn upload_post_form(
i18n: I18n,
data: Data<'_>,
) -> MyResponse {
- match process_post_form(&db, &tokens_stateless, &rate_limiter, &i18n, data).await {
+ match process_post_form(db, tokens_stateless, rate_limiter, &i18n, data).await {
Ok(response) => MyResponse::upload_response(response,
i18n, origin),
Err(err) => MyResponse::bad_request("upload/upload", err,
@@ -349,10 +349,10 @@ pub async fn process_post_form(
match name.to_string().as_str() {
"keytext" => {
return Ok(vks::process_key(
- &db,
- &i18n,
- &tokens_stateless,
- &rate_limiter,
+ db,
+ i18n,
+ tokens_stateless,
+ rate_limiter,
Cursor::new(decoded_value.as_bytes())
));
}