Present desktop OTP and sensitive outputs
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use std::{
|
||||
error::Error,
|
||||
io::Cursor,
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
@@ -229,3 +230,39 @@ fn qr_matrices_round_trip_and_render_without_plaintext() -> TestResult {
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn qr_image_import_returns_secret_bytes_and_rejects_invalid_input() -> TestResult {
|
||||
let payload = SecretBytes::new(
|
||||
b"otpauth://totp/Example:alice?secret=JBSWY3DPEHPK3PXP&issuer=Example".to_vec(),
|
||||
);
|
||||
let matrix = QrMatrix::encode(&payload)?;
|
||||
let scale = 8_u32;
|
||||
let quiet = 4_u32;
|
||||
let size = (matrix.width() as u32 + quiet * 2) * scale;
|
||||
let mut image = image::GrayImage::from_pixel(size, size, image::Luma([255]));
|
||||
for y in 0..matrix.width() {
|
||||
for x in 0..matrix.width() {
|
||||
if matrix.is_dark(x, y) == Some(true) {
|
||||
for dy in 0..scale {
|
||||
for dx in 0..scale {
|
||||
image.put_pixel(
|
||||
(x as u32 + quiet) * scale + dx,
|
||||
(y as u32 + quiet) * scale + dy,
|
||||
image::Luma([0]),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut encoded = Cursor::new(Vec::new());
|
||||
image.write_to(&mut encoded, image::ImageFormat::Png)?;
|
||||
let decoded = QrMatrix::decode_image(&SecretBytes::new(encoded.into_inner()))?;
|
||||
assert_eq!(decoded.expose(), payload.expose());
|
||||
assert!(matches!(
|
||||
QrMatrix::decode_image(&SecretBytes::new(b"not an image".to_vec())),
|
||||
Err(QrError::InvalidImage)
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user