Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

fix(cli): validate page positions and preserve command results (M13) (#391)

sanyamsingh0019c63f3e8f214
diff --git a/apps/pdfcraft-cli/src/main.rs b/apps/pdfcraft-cli/src/main.rs
index 3c05c0c4b..3fe28824d 100644
--- a/apps/pdfcraft-cli/src/main.rs
+++ b/apps/pdfcraft-cli/src/main.rs
@@ -176,6 +176,22 @@ fn info(args: &[String]) -> Result<(), CliError> {
fn text(args: &[String]) -> Result<(), CliError> {
let path = *positional(args).first().ok_or("text: missing file")?;
+ let mut selected_page = None;
+ // Validate every supplied value before reading, retaining the first valid selection.
+ let mut options = args.iter();
+ while let Some(option) = options.next() {
+ if option == "--page" {
+ let page = options
+ .next()
+ .and_then(|value| value.parse::<usize>().ok())
+ .filter(|page| *page > 0)
+ .ok_or("bad --page: expected a positive page number")?;
+ selected_page.get_or_insert(page - 1);
+ } else if option.starts_with("--") {
+ // Match positional(): an option's operand is not itself another option.
+ options.next();
+ }
+ }
let password = flag(args, "--password");
let bytes = read(path)?;
let mut r = PageRenderer::new(bytes.clone(), RenderConfig { password: password.map(Arc::from), ..Default::default() });
@@ -188,15 +204,15 @@ fn text(args: &[String]) -> Result<(), CliError> {
return Err("text: the document could not be parsed".into());
}
}
- let pages: Vec<usize> = match flag(args, "--page") {
- Some(p) => vec![p.parse::<usize>().map_err(|_| "bad --page")?.saturating_sub(1)],
+ let pages: Vec<usize> = match selected_page {
+ Some(page) => vec![page],
None => (0..r.page_count()).collect(),
};
let mut failed: Vec<usize> = Vec::new();
for (n, p) in pages.iter().enumerate() {
let out = r.render(RenderRequest { page: *p, kind: RequestKind::Text, tile: None, scale: 1.0, tag: 0 });
if let Some(e) = out.error {
- eprintln!("page {}: {e}", p + 1);
+ let _ = writeln!(std::io::stderr().lock(), "page {}: {e}", p + 1);
failed.push(p + 1);
continue;
}
@@ -263,11 +279,11 @@ fn edit(args: &[String]) -> Result<(), CliError> {
"--move" => {
let (pages, to) = value.split_once(':').ok_or("--move PAGES:TO")?;
let to: usize = to.parse().map_err(|_| "bad target")?;
- edits.push(Edit::MovePages { pages: page_list(pages)?, to: to.saturating_sub(1) });
+ edits.push(Edit::MovePages { pages: page_list(pages)?, to: to.checked_sub(1).ok_or("--move target must be at least 1")? });
}
"--insert-blank" => {
let at: usize = value.parse().map_err(|_| "bad position")?;
- edits.push(Edit::InsertBlankPage { at: at.saturating_sub(1), width: 612.0, height: 792.0 });
+ edits.push(Edit::InsertBlankPage { at: at.checked_sub(1).ok_or("--insert-blank must be at least 1")?, width: 612.0, height: 792.0 });
}
"--title" => edits.push(Edit::SetInfo { key: "Title".into(), value: value.into() }),
"--author" => edits.push(Edit::SetInfo { key: "Author".into(), value: value.into() }),
@@ -338,6 +354,7 @@ fn split(args: &[String]) -> Result<(), CliError> {
fn render(args: &[String]) -> Result<(), CliError> {
let path = *positional(args).first().ok_or("render: missing file")?;
let page: usize = flag(args, "--page").unwrap_or("1").parse().map_err(|_| "bad --page")?;
+ let page_index = page.checked_sub(1).ok_or("--page must be at least 1")?;
let dpi: f32 = flag(args, "--dpi").unwrap_or("96").parse().map_err(|_| "bad --dpi")?;
let out = flag(args, "--out").ok_or("render: missing --out (.png, .jpg, .tif or .pam)")?;
// The file is what its name says (#248): a `.png` used to get a netpbm PAM stream.
@@ -349,7 +366,7 @@ fn render(args: &[String]) -> Result<(), CliError> {
_ => return Err(format!("render: --out {out}: use a .png, .jpg, .tif or .pam name").into()),
};
let mut r = PageRenderer::new(read(path)?, RenderConfig { password: flag(args, "--password").map(Arc::from), ..Default::default() });
- let p = r.render(RenderRequest { page: page.saturating_sub(1), kind: RequestKind::Pixels, tile: None, scale: dpi / 72.0, tag: 0 });
+ let p = r.render(RenderRequest { page: page_index, kind: RequestKind::Pixels, tile: None, scale: dpi / 72.0, tag: 0 });
if let Some(e) = p.error {
return Err(e.into());
}
@@ -363,7 +380,7 @@ fn render(args: &[String]) -> Result<(), CliError> {
}
};
std::fs::write(out, bytes).map_err(|e| format!("{out}: {e}"))?;
- eprintln!("rendered page {page} at {dpi} dpi: {}×{} px in {} ms", p.width, p.height, p.millis);
+ let _ = writeln!(std::io::stderr().lock(), "rendered page {page} at {dpi} dpi: {}×{} px in {} ms", p.width, p.height, p.millis);
Ok(())
}
@@ -582,7 +599,8 @@ fn run(args: &[String]) -> Result<(), CliError> {
fn mcp(args: &[String]) -> Result<(), CliError> {
let compact = args.iter().any(|a| a == "--compact");
let mut server = pdfcraft_automation::mcp::McpServer::new(automation(args)?).with_compact(compact);
- eprintln!(
+ let _ = writeln!(
+ std::io::stderr().lock(),
"pdfcraft-cli: MCP server on stdio (protocol {}{}); close stdin to stop",
pdfcraft_automation::mcp::PROTOCOL_VERSIONS[0],
if compact { ", compact tool list" } else { "" }
diff --git a/apps/pdfcraft-cli/tests/edit.rs b/apps/pdfcraft-cli/tests/edit.rs
index 8cd47cfbd..15fdb68c1 100644
--- a/apps/pdfcraft-cli/tests/edit.rs
+++ b/apps/pdfcraft-cli/tests/edit.rs
@@ -91,3 +91,91 @@ fn the_documented_options_still_edit_and_save() {
assert_eq!(info.title.as_deref(), Some("Rotated"), "{name}");
}
}
+
+mod one_based_arguments {
+ use super::*;
+ use std::sync::atomic::{AtomicU64, Ordering};
+
+ struct TestDir(PathBuf);
+ impl TestDir {
+ fn new() -> Self {
+ static NEXT: AtomicU64 = AtomicU64::new(0);
+ for _ in 0..128 {
+ let path =
+ std::env::temp_dir().join(format!("pdfcraft-cli-one-based-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed)));
+ match std::fs::create_dir(&path) {
+ Ok(()) => return Self(path),
+ Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
+ Err(e) => panic!("cannot create test directory: {e}"),
+ }
+ }
+ panic!("cannot reserve test directory");
+ }
+ }
+ impl Drop for TestDir {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_dir_all(&self.0);
+ }
+ }
+
+ #[test]
+ fn zero_render_page_and_edit_positions_fail_before_io() {
+ let dir = TestDir::new();
+ let source = fixture();
+ std::fs::write(dir.0.join("input.pdf"), &source).unwrap();
+ for input in ["input.pdf", "missing.pdf"] {
+ for destination in ["output.pam", "new.pam", "input.pdf"] {
+ std::fs::write(dir.0.join("output.pam"), b"keep destination").unwrap();
+ for (command, option, value, diagnostic) in [
+ ("render", "--page", "0", "--page must be at least 1"),
+ ("edit", "--move", "1:0", "--move target must be at least 1"),
+ ("edit", "--insert-blank", "0", "--insert-blank must be at least 1"),
+ ] {
+ let out = Command::new(BIN).current_dir(&dir.0).args([command, input, "--out", destination, option, value]).output().unwrap();
+ assert_eq!(out.status.code(), Some(1), "{command} {input} {option} {value}");
+ assert_eq!(out.stderr, format!("pdfcraft-cli: {diagnostic}\n").as_bytes());
+ assert!(out.stdout.is_empty());
+ assert_eq!(std::fs::read(dir.0.join("input.pdf")).unwrap(), source);
+ assert_eq!(std::fs::read(dir.0.join("output.pam")).unwrap(), b"keep destination");
+ assert!(!dir.0.join("new.pam").exists());
+ assert!(!dir.0.join("missing.pdf").exists());
+ }
+ }
+ }
+ assert_eq!(std::fs::read_dir(&dir.0).unwrap().count(), 2);
+ }
+
+ #[test]
+ fn first_render_page_move_target_and_insertion_position_remain_usable() {
+ let dir = TestDir::new();
+ let source = fixture();
+ std::fs::write(dir.0.join("input.pdf"), &source).unwrap();
+ for output in ["page.pam", "page.png"] {
+ let out =
+ Command::new(BIN).current_dir(&dir.0).args(["render", "input.pdf", "--page", "1", "--dpi", "18", "--out", output]).output().unwrap();
+ assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
+ let bytes = std::fs::read(dir.0.join(output)).unwrap();
+ if output.ends_with(".pam") {
+ let header = b"P7\nWIDTH 50\nHEIGHT 75\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n";
+ assert!(bytes.starts_with(header));
+ assert_eq!(bytes.len(), header.len() + 50 * 75 * 4);
+ } else {
+ assert!(bytes.starts_with(b"\x89PNG\r\n\x1a\n"));
+ assert_eq!(u32::from_be_bytes(bytes[16..20].try_into().unwrap()), 50);
+ assert_eq!(u32::from_be_bytes(bytes[20..24].try_into().unwrap()), 75);
+ }
+ }
+ let out = Command::new(BIN)
+ .current_dir(&dir.0)
+ .args(["edit", "input.pdf", "--out", "edited.pdf", "--move", "1:1", "--rotate", "1:90", "--insert-blank", "1"])
+ .output()
+ .unwrap();
+ assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
+ assert!(out.stdout.is_empty() && out.stderr.is_empty());
+ let info = pdfcraft_render::inspect(std::sync::Arc::new(std::fs::read(dir.0.join("edited.pdf")).unwrap()), None).unwrap();
+ assert_eq!(info.pages.len(), 2);
+ assert_eq!((info.pages[0].width, info.pages[0].height, info.pages[0].rotation), (612.0, 792.0, 0));
+ assert_eq!((info.pages[1].width, info.pages[1].height, info.pages[1].rotation), (300.0, 200.0, 90));
+ assert_eq!(std::fs::read(dir.0.join("input.pdf")).unwrap(), source);
+ }
+}
diff --git a/apps/pdfcraft-cli/tests/stderr.rs b/apps/pdfcraft-cli/tests/stderr.rs
new file mode 100644
index 000000000..9991bc1cf
--- /dev/null
+++ b/apps/pdfcraft-cli/tests/stderr.rs
@@ -0,0 +1,132 @@
+//! Diagnostic stderr failures must not replace a command's real result.
+#![cfg(target_os = "linux")]
+
+use std::io::Write as _;
+use std::path::{Path, PathBuf};
+use std::process::{Child, Command, Output, Stdio};
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::time::{Duration, Instant};
+
+const BIN: &str = env!("CARGO_BIN_EXE_pdfcraft-cli");
+
+struct Scratch(PathBuf);
+impl Scratch {
+ fn new() -> Self {
+ static NEXT: AtomicU64 = AtomicU64::new(0);
+ for _ in 0..128 {
+ let path = std::env::temp_dir().join(format!("pdfcraft-stderr-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed)));
+ match std::fs::create_dir(&path) {
+ Ok(()) => return Self(path),
+ Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
+ Err(error) => panic!("creating stderr test directory: {error}"),
+ }
+ }
+ panic!("no unused stderr test directory after 128 attempts");
+ }
+}
+impl Drop for Scratch {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_dir_all(&self.0);
+ }
+}
+
+// Only this test's newly spawned child is ever terminated, including assertion unwinding.
+struct OwnedChild(Option<Child>);
+impl Drop for OwnedChild {
+ fn drop(&mut self) {
+ if let Some(child) = &mut self.0 {
+ let _ = child.kill();
+ let _ = child.wait();
+ }
+ }
+}
+fn run(command: &mut Command, input: Option<&str>) -> Output {
+ command.stdin(if input.is_some() { Stdio::piped() } else { Stdio::null() });
+ let mut owned = OwnedChild(Some(command.spawn().unwrap()));
+ if let Some(input) = input {
+ owned.0.as_mut().unwrap().stdin.take().unwrap().write_all(input.as_bytes()).unwrap();
+ }
+ // Every fixture emits only a few short lines, below the pipe capacity.
+ let deadline = Instant::now() + Duration::from_secs(30);
+ while owned.0.as_mut().unwrap().try_wait().unwrap().is_none() {
+ assert!(Instant::now() < deadline, "owned CLI child exceeded thirty seconds");
+ std::thread::sleep(Duration::from_millis(10));
+ }
+ owned.0.take().unwrap().wait_with_output().unwrap()
+}
+fn full() -> Stdio {
+ std::fs::OpenOptions::new().write(true).open("/dev/full").unwrap().into()
+}
+fn render(pdf: &Path, out: &Path, stderr: Stdio) -> Output {
+ run(Command::new(BIN).arg("render").arg(pdf).args(["--page", "1", "--dpi", "18", "--out"]).arg(out).stdout(Stdio::piped()).stderr(stderr), None)
+}
+
+#[test]
+fn failing_diagnostics_preserve_render_success_and_real_text_or_file_errors() {
+ let dir = Scratch::new();
+ let bytes = pdfcraft_engine::Session::new().create_from_text("Diagnostic test", "Ordinary diagnostic text").unwrap();
+ let pdf = dir.0.join("input.pdf");
+ std::fs::write(&pdf, bytes.as_slice()).unwrap();
+ let image_path = dir.0.join("page.pam");
+ let failed_sink = render(&pdf, &image_path, full());
+ assert!(failed_sink.status.success(), "completed render must survive failed diagnostics: {}", failed_sink.status);
+ assert!(failed_sink.stdout.is_empty());
+ let image = std::fs::read(&image_path).unwrap();
+ assert!(image.starts_with(b"P7\nWIDTH ") && image.windows(7).any(|part| part == b"ENDHDR\n"));
+ let ordinary = render(&pdf, &image_path, Stdio::piped());
+ assert!(ordinary.status.success());
+ assert!(String::from_utf8_lossy(&ordinary.stderr).contains("rendered page 1 at 18 dpi"));
+ assert_eq!(std::fs::read(&image_path).unwrap(), image, "diagnostic destination must not change rendered bytes");
+
+ let invalid = run(Command::new(BIN).arg("text").arg(&pdf).args(["--page", "2"]).stdout(Stdio::piped()).stderr(full()), None);
+ assert_eq!(invalid.status.code(), Some(1), "page errors remain normal failures rather than stderr panics");
+ assert!(invalid.stdout.is_empty());
+ let valid = run(Command::new(BIN).arg("text").arg(&pdf).stdout(Stdio::piped()).stderr(full()), None);
+ assert!(valid.status.success());
+ assert!(String::from_utf8_lossy(&valid.stdout).contains("Ordinary diagnostic text"));
+
+ // An existing directory with a supported extension reaches the real file writer.
+ // Using /dev/full as the render path would only test upstream's extension check.
+ let folder = dir.0.join("folder.pam");
+ std::fs::create_dir(&folder).unwrap();
+ std::fs::write(folder.join("keep"), b"sentinel").unwrap();
+ assert_eq!(render(&pdf, &folder, full()).status.code(), Some(1));
+ assert_eq!(std::fs::read(folder.join("keep")).unwrap(), b"sentinel");
+ assert_eq!(std::fs::read(&image_path).unwrap(), image);
+ assert_eq!(std::fs::read(&pdf).unwrap(), bytes.as_slice());
+}
+
+#[cfg(feature = "mcp")]
+#[test]
+fn failing_startup_diagnostics_preserve_mcp_replies_and_protocol_output_errors() {
+ let requests = [
+ serde_json::json!({ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2025-06-18" } }),
+ serde_json::json!({ "jsonrpc": "2.0", "id": 2, "method": "ping" }),
+ serde_json::json!({ "jsonrpc": "2.0", "id": 3, "method": "ordinary-unknown-method" }),
+ ];
+ let input = requests.iter().map(|request| format!("{request}\n")).collect::<String>();
+ let output = run(Command::new(BIN).arg("mcp").stdout(Stdio::piped()).stderr(full()), Some(&input));
+ assert!(output.status.success(), "failed startup diagnostics must not stop stdio: {}", output.status);
+ let replies: Vec<serde_json::Value> = String::from_utf8(output.stdout).unwrap().lines().map(|line| serde_json::from_str(line).unwrap()).collect();
+ assert_eq!(replies.len(), 3);
+ assert_eq!(replies[0]["id"], 1);
+ assert_eq!(replies[0]["result"]["protocolVersion"], "2025-06-18");
+ assert_eq!(replies[1]["id"], 2);
+ assert_eq!(replies[1]["result"], serde_json::json!({}));
+ assert_eq!(replies[2]["id"], 3);
+ assert_eq!(replies[2]["error"]["code"], -32601);
+ // Upstream's compact mode still reaches stdio even when its expanded diagnostic fails.
+ let ping = "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"ping\"}\n";
+ for (stderr, diagnostic_expected) in [(full(), false), (Stdio::piped(), true)] {
+ let output = run(Command::new(BIN).args(["mcp", "--compact"]).stdout(Stdio::piped()).stderr(stderr), Some(ping));
+ assert!(output.status.success());
+ let reply: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
+ assert_eq!(reply["id"], 4);
+ assert_eq!(reply["result"], serde_json::json!({}));
+ if diagnostic_expected {
+ assert!(String::from_utf8_lossy(&output.stderr).contains(", compact tool list); close stdin to stop"));
+ }
+ }
+ let output = run(Command::new(BIN).arg("mcp").stdout(full()).stderr(full()), Some("{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"ping\"}\n"));
+ assert_eq!(output.status.code(), Some(1), "actual protocol output failure must still fail");
+}
diff --git a/apps/pdfcraft-cli/tests/text.rs b/apps/pdfcraft-cli/tests/text.rs
index c573393b2..5ac2e07c7 100644
--- a/apps/pdfcraft-cli/tests/text.rs
+++ b/apps/pdfcraft-cli/tests/text.rs
@@ -95,3 +95,117 @@ fn text_of_a_protected_document_with_the_password_succeeds() {
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(stdout.contains("Page 1") && stdout.contains("Page 3"), "{stdout}");
}
+
+mod page_argument_tests {
+ use super::*;
+ use std::path::PathBuf;
+ use std::sync::atomic::{AtomicU64, Ordering};
+
+ struct PageDir(PathBuf);
+
+ impl PageDir {
+ fn new() -> Self {
+ static NEXT: AtomicU64 = AtomicU64::new(0);
+ for _ in 0..128 {
+ let serial = NEXT.fetch_add(1, Ordering::Relaxed);
+ let path = std::env::temp_dir().join(format!("pdfcraft-page-{}-{serial}", std::process::id()));
+ match std::fs::create_dir(&path) {
+ Ok(()) => return Self(path),
+ Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
+ Err(error) => panic!("creating page test directory: {error}"),
+ }
+ }
+ panic!("no unused page test directory after 128 attempts");
+ }
+ }
+
+ impl Drop for PageDir {
+ fn drop(&mut self) {
+ let _ = std::fs::remove_dir_all(&self.0);
+ }
+ }
+
+ #[test]
+ fn malformed_page_values_fail_before_reading_or_printing_document_text() {
+ let dir = PageDir::new();
+ let path = dir.0.join("three.pdf");
+ let bytes = fixture(3);
+ std::fs::write(&path, &bytes).unwrap();
+ let missing = dir.0.join("missing.pdf");
+ let invalid = [
+ vec!["--page", "0"],
+ vec!["--page", ""],
+ vec!["--page", "bad"],
+ vec!["--page", "-1"],
+ vec!["--page", "1.5"],
+ vec!["--page", "18446744073709551616"],
+ vec!["--page"],
+ vec!["--page", "--password", "unused"],
+ vec!["--page", "2", "--page"],
+ ];
+ for input in [&path, &missing] {
+ for args in &invalid {
+ let out = Command::new(BIN).arg("text").arg(input).args(args).output().unwrap();
+ assert_eq!(out.status.code(), Some(1), "{args:?}: {out:?}");
+ assert!(out.stdout.is_empty(), "{args:?}: no text may be printed");
+ assert_eq!(String::from_utf8(out.stderr).unwrap().trim(), "pdfcraft-cli: bad --page: expected a positive page number");
+ assert_eq!(std::fs::read(&path).unwrap(), bytes);
+ assert!(!missing.exists());
+ }
+ }
+ }
+
+ #[test]
+ fn valid_page_values_preserve_all_page_selection_and_first_duplicate_semantics() {
+ let dir = PageDir::new();
+ let path = dir.0.join("three.pdf");
+ let bytes = fixture(3);
+ std::fs::write(&path, &bytes).unwrap();
+ for (args, expected) in [
+ (vec![], vec!["Page 1", "Page 2", "Page 3"]),
+ (vec!["--page", "1"], vec!["Page 1"]),
+ (vec!["--page", "2"], vec!["Page 2"]),
+ (vec!["--page", "3"], vec!["Page 3"]),
+ (vec!["--page", "2", "--page", "1"], vec!["Page 2"]),
+ ] {
+ let out = Command::new(BIN).arg("text").arg(&path).args(args).output().unwrap();
+ assert!(out.status.success(), "{out:?}");
+ assert!(out.stderr.is_empty());
+ let text = String::from_utf8(out.stdout).unwrap();
+ assert_eq!(text.split(' ').map(str::trim).collect::<Vec<_>>(), expected);
+ assert_eq!(std::fs::read(&path).unwrap(), bytes);
+ }
+ }
+
+ #[test]
+ fn an_option_shaped_password_is_not_parsed_as_a_page_flag() {
+ let dir = PageDir::new();
+ let source = dir.0.join("three.pdf");
+ let bytes = fixture(3);
+ std::fs::write(&source, &bytes).unwrap();
+ let protected = dir.0.join("protected.pdf");
+ let script = dir.0.join("protect.json");
+ let steps = serde_json::json!([
+ { "tool": "doc_open", "args": { "path": source } },
+ { "tool": "doc_protect", "args": { "doc": 1, "open_password": "--page" } },
+ { "tool": "doc_save", "args": { "doc": 1, "path": protected } },
+ ]);
+ std::fs::write(&script, steps.to_string()).unwrap();
+ let out = Command::new(BIN).args(["run", "--script"]).arg(&script).output().unwrap();
+ assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr));
+ let protected_bytes = std::fs::read(&protected).unwrap();
+ for (args, expected) in [
+ (vec!["--password", "--page"], vec!["Page 1", "Page 2", "Page 3"]),
+ (vec!["--page", "2", "--password", "--page"], vec!["Page 2"]),
+ (vec!["--password", "--page", "--page", "2"], vec!["Page 2"]),
+ ] {
+ let out = Command::new(BIN).arg("text").arg(&protected).args(args).output().unwrap();
+ assert!(out.status.success(), "{out:?}");
+ assert!(out.stderr.is_empty());
+ let text = String::from_utf8(out.stdout).unwrap();
+ assert_eq!(text.split(' ').map(str::trim).collect::<Vec<_>>(), expected);
+ assert_eq!(std::fs::read(&protected).unwrap(), protected_bytes);
+ assert_eq!(std::fs::read(&source).unwrap(), bytes);
+ }
+ }
+}