mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add test routine for QR code generation/scan
a 40-byte message can be encoded in a version 3 code with medium ECC. This is pretty optimal because it allows 4 pixels per module in the QR code, which is a nice size for viewing. base45 is added as a dependency to the project. Base45 is weird but apparently it's the most efficient way to code binary data into a QR code. 40 bytes (320 bits) is enough to exchange a 256-bit key plus 64 bits of sideband data. I think this is going to be enough for basic device-to-device handshaking.
This commit is contained in:
parent
c813aa1b92
commit
c3a0a50c9e
3 changed files with 43 additions and 0 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -360,6 +360,7 @@ dependencies = [
|
||||||
"bao1x-emu",
|
"bao1x-emu",
|
||||||
"bao1x-hal",
|
"bao1x-hal",
|
||||||
"bao1x-hal-service",
|
"bao1x-hal-service",
|
||||||
|
"base45",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -612,6 +613,12 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa"
|
checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base45"
|
||||||
|
version = "3.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b3103f6d6af63726e86b026ac66769fc578ea38aba33f409e5855a4def97a564"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@ aes = { path = "../aes", default-features = false, optional = true, features = [
|
||||||
# time testing
|
# time testing
|
||||||
chrono = "0.4.33"
|
chrono = "0.4.33"
|
||||||
|
|
||||||
|
# QR code encoding
|
||||||
|
base45 = "3.1.0"
|
||||||
|
|
||||||
# hid bringup
|
# hid bringup
|
||||||
xous-usb-hid = { git = "https://github.com/betrusted-io/xous-usb-hid.git", branch = "main", optional = true }
|
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",
|
"usb-bao1x/board-baosec",
|
||||||
"pddb/board-baosec",
|
"pddb/board-baosec",
|
||||||
"xous-swapper",
|
"xous-swapper",
|
||||||
|
"ux-api/board-baosec",
|
||||||
]
|
]
|
||||||
hosted-baosec = [
|
hosted-baosec = [
|
||||||
"modals/hosted-baosec",
|
"modals/hosted-baosec",
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,38 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
"keepon" => {
|
"keepon" => {
|
||||||
todo!("Fix this to use DCDC2 for keepon (as per baosec v2)");
|
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();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue