[pbs-devel] [PATCH pbs 1/2] pbs-datastore: paperkey: Add padding to utf8 qrcodes

Maximiliano Sandoval m.sandoval at proxmox.com
Tue Jun 13 12:47:29 CEST 2023


Many QR code scanners, including ZBar for example, cannot read qr codes
properly when there is not padding around them.

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 pbs-datastore/src/paperkey.rs | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/pbs-datastore/src/paperkey.rs b/pbs-datastore/src/paperkey.rs
index 14b62264..6d8cd914 100644
--- a/pbs-datastore/src/paperkey.rs
+++ b/pbs-datastore/src/paperkey.rs
@@ -226,8 +226,12 @@ fn paperkey_text<W: Write>(
 }
 
 fn generate_qr_code(output_type: &str, lines: &[String]) -> Result<Vec<u8>, Error> {
+    let padding = match output_type {
+        "utf8" | "utf8i" => "-m2",
+        _ => "-m0",
+    };
     let mut child = Command::new("qrencode")
-        .args(["-t", output_type, "-m0", "-s1", "-lm", "--output", "-"])
+        .args(["-t", output_type, padding, "-s1", "-lm", "--output", "-"])
         .stdin(Stdio::piped())
         .stdout(Stdio::piped())
         .spawn()?;
-- 
2.39.2






More information about the pbs-devel mailing list