public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 3/3] paperkey: rustfmt
Date: Mon,  1 Feb 2021 14:06:18 +0100	[thread overview]
Message-ID: <20210201130618.800923-3-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20210201130618.800923-1-f.gruenbichler@proxmox.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
 src/tools/paperkey.rs | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/tools/paperkey.rs b/src/tools/paperkey.rs
index 3c1f7c91..2dc185a8 100644
--- a/src/tools/paperkey.rs
+++ b/src/tools/paperkey.rs
@@ -1,5 +1,5 @@
 use std::io::Write;
-use std::process::{Stdio, Command};
+use std::process::{Command, Stdio};
 
 use anyhow::{bail, format_err, Error};
 use serde::{Deserialize, Serialize};
@@ -61,11 +61,11 @@ pub fn generate_paper_key<W: Write>(
                     .collect();
 
                 (lines, false)
-            },
+            }
             Err(err) => {
                 eprintln!("Couldn't parse data as KeyConfig - {}", err);
                 bail!("Neither a PEM-formatted private key, nor a PBS key file.");
-            },
+            }
         }
     };
 
@@ -83,14 +83,16 @@ fn paperkey_html<W: Write>(
     subject: Option<String>,
     is_master: bool,
 ) -> Result<(), Error> {
-
     let img_size_pt = 500;
 
     writeln!(output, "<!DOCTYPE html>")?;
     writeln!(output, "<html lang=\"en\">")?;
     writeln!(output, "<head>")?;
     writeln!(output, "<meta charset=\"utf-8\">")?;
-    writeln!(output, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")?;
+    writeln!(
+        output,
+        "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">"
+    )?;
     writeln!(output, "<title>Proxmox Backup Paperkey</title>")?;
     writeln!(output, "<style type=\"text/css\">")?;
 
@@ -115,7 +117,10 @@ fn paperkey_html<W: Write>(
         const BLOCK_SIZE: usize = 20;
 
         for (block_nr, block) in lines.chunks(BLOCK_SIZE).enumerate() {
-            writeln!(output, "<div style=\"page-break-inside: avoid;page-break-after: always\">")?;
+            writeln!(
+                output,
+                "<div style=\"page-break-inside: avoid;page-break-after: always\">"
+            )?;
             writeln!(output, "<p>")?;
 
             for (i, line) in block.iter().enumerate() {
@@ -129,11 +134,15 @@ fn paperkey_html<W: Write>(
 
             writeln!(output, "<center>")?;
             writeln!(output, "<img")?;
-            writeln!(output, "width=\"{}pt\" height=\"{}pt\"", img_size_pt, img_size_pt)?;
+            writeln!(
+                output,
+                "width=\"{}pt\" height=\"{}pt\"",
+                img_size_pt, img_size_pt
+            )?;
             writeln!(output, "src=\"data:image/svg+xml;base64,{}\"/>", qr_code)?;
             writeln!(output, "</center>")?;
             writeln!(output, "</div>")?;
-       }
+        }
 
         writeln!(output, "</body>")?;
         writeln!(output, "</html>")?;
@@ -159,7 +168,11 @@ fn paperkey_html<W: Write>(
 
     writeln!(output, "<center>")?;
     writeln!(output, "<img")?;
-    writeln!(output, "width=\"{}pt\" height=\"{}pt\"", img_size_pt, img_size_pt)?;
+    writeln!(
+        output,
+        "width=\"{}pt\" height=\"{}pt\"",
+        img_size_pt, img_size_pt
+    )?;
     writeln!(output, "src=\"data:image/svg+xml;base64,{}\"/>", qr_code)?;
     writeln!(output, "</center>")?;
 
@@ -177,7 +190,6 @@ fn paperkey_text<W: Write>(
     subject: Option<String>,
     is_private: bool,
 ) -> Result<(), Error> {
-
     if let Some(subject) = subject {
         writeln!(output, "Subject: {}\n", subject)?;
     }
@@ -194,7 +206,6 @@ fn paperkey_text<W: Write>(
                 .map_err(|_| format_err!("Failed to read qr code (got non-utf8 data)"))?;
             writeln!(output, "{}", qr_code)?;
             writeln!(output, "{}", char::from(12u8))?; // page break
-
         }
         return Ok(());
     }
@@ -222,14 +233,18 @@ fn generate_qr_code(output_type: &str, lines: &[String]) -> Result<Vec<u8>, Erro
         .spawn()?;
 
     {
-        let stdin = child.stdin.as_mut()
+        let stdin = child
+            .stdin
+            .as_mut()
             .ok_or_else(|| format_err!("Failed to open stdin"))?;
         let data = lines.join("\n");
-        stdin.write_all(data.as_bytes())
+        stdin
+            .write_all(data.as_bytes())
             .map_err(|_| format_err!("Failed to write to stdin"))?;
     }
 
-    let output = child.wait_with_output()
+    let output = child
+        .wait_with_output()
         .map_err(|_| format_err!("Failed to read stdout"))?;
 
     let output = crate::tools::command_output(output, None)?;
-- 
2.20.1





  parent reply	other threads:[~2021-02-01 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-01 13:06 [pbs-devel] [PATCH proxmox-backup 1/3] paperkey: allow RSA keys without passphrase Fabian Grünbichler
2021-02-01 13:06 ` [pbs-devel] [PATCH proxmox-backup 2/3] paperkey: simplify block generation Fabian Grünbichler
2021-02-01 13:06 ` Fabian Grünbichler [this message]
2021-02-01 16:05 ` [pbs-devel] applied: [PATCH proxmox-backup 1/3] paperkey: allow RSA keys without passphrase Dietmar Maurer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210201130618.800923-3-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal