diff --git a/Cargo.lock b/Cargo.lock index 65e418870..f94d128b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -360,6 +360,7 @@ dependencies = [ "bao1x-emu", "bao1x-hal", "bao1x-hal-service", + "base45", "bytemuck", "chrono", "log", @@ -612,6 +613,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" +[[package]] +name = "base45" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3103f6d6af63726e86b026ac66769fc578ea38aba33f409e5855a4def97a564" + [[package]] name = "base64" version = "0.5.2" diff --git a/services/bao-console/Cargo.toml b/services/bao-console/Cargo.toml index 3ea4729c1..75a793921 100644 --- a/services/bao-console/Cargo.toml +++ b/services/bao-console/Cargo.toml @@ -37,6 +37,9 @@ aes = { path = "../aes", default-features = false, optional = true, features = [ # time testing chrono = "0.4.33" +# QR code encoding +base45 = "3.1.0" + # hid bringup xous-usb-hid = { git = "https://github.com/betrusted-io/xous-usb-hid.git", branch = "main", optional = true } @@ -50,6 +53,7 @@ board-baosec = [ "usb-bao1x/board-baosec", "pddb/board-baosec", "xous-swapper", + "ux-api/board-baosec", ] hosted-baosec = [ "modals/hosted-baosec", diff --git a/services/bao-console/src/cmds/test.rs b/services/bao-console/src/cmds/test.rs index d36574836..67131458d 100644 --- a/services/bao-console/src/cmds/test.rs +++ b/services/bao-console/src/cmds/test.rs @@ -128,6 +128,38 @@ impl<'a> ShellCmdApi<'a> for Test { "keepon" => { todo!("Fix this to use DCDC2 for keepon (as per baosec v2)"); } + "qrshow" => { + let modals = modals::Modals::new(&_env.xns).unwrap(); + let mut test_data = [0u8; 40]; + for (i, d) in test_data.iter_mut().enumerate() { + *d = i as u8; + } + let encoded = base45::encode(&test_data); + modals.show_notification("", Some(&encoded)).ok(); + } + "qrget" => { + let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap(); + match gfx.acquire_qr() { + Ok(qr_data) => { + if let Some(meta) = qr_data.meta { + log::info!("QR code metadata: {}", meta); + } + if let Some(coded) = qr_data.content { + match base45::decode(&coded) { + Ok(data) => { + log::info!("Recovered: {:x?}", data); + } + Err(e) => { + log::info!("Base45 decode err: {:?}", e); + } + } + } + } + Err(e) => { + log::info!("QR error: {:?}", e); + } + } + } _ => { write!(ret, "{}", helpstring).unwrap(); }