-
-
Notifications
You must be signed in to change notification settings - Fork 2
Lib/add hashed password #2932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Lib/add hashed password #2932
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -269,6 +269,7 @@ fn compare_entry<T: AsRef<[u8]>>( | |
| let data_kind = entry.header().data_kind(); | ||
| let path = entry.header().path(); | ||
| let path_str = path.as_str(); | ||
| let mut read_options = ReadOptions::with_password(password); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating a new |
||
| let meta = match fs::symlink_metadata(path) { | ||
| Ok(meta) => meta, | ||
| Err(e) if e.kind() == io::ErrorKind::NotFound => { | ||
|
|
@@ -292,7 +293,7 @@ fn compare_entry<T: AsRef<[u8]>>( | |
| println!("{}", DiffKind::SizeDiffers.display(path_str)); | ||
| } else { | ||
| let fs_file = fs::File::open(path)?; | ||
| let archive_reader = entry.reader(ReadOptions::with_password(password))?; | ||
| let archive_reader = entry.reader(&mut read_options)?; | ||
| if !streams_equal(fs_file, archive_reader)? { | ||
| println!("{}", DiffKind::ContentsDiffer.display(path_str)); | ||
| } | ||
|
|
@@ -306,7 +307,7 @@ fn compare_entry<T: AsRef<[u8]>>( | |
| } | ||
| DataKind::SymbolicLink if meta.is_symlink() => { | ||
| let link = fs::read_link(path)?; | ||
| let mut reader = entry.reader(ReadOptions::with_password(password))?; | ||
| let mut reader = entry.reader(&mut read_options)?; | ||
| let mut link_str = String::new(); | ||
| reader.read_to_string(&mut link_str)?; | ||
| if link.as_path() != Path::new(&link_str) { | ||
|
|
@@ -317,7 +318,7 @@ fn compare_entry<T: AsRef<[u8]>>( | |
| println!("{}", DiffKind::TypeMismatch.display(path_str)); | ||
| } | ||
| DataKind::HardLink if meta.is_file() => { | ||
| let mut reader = entry.reader(ReadOptions::with_password(password))?; | ||
| let mut reader = entry.reader(&mut read_options)?; | ||
| let mut target = String::new(); | ||
| reader.read_to_string(&mut target)?; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -609,7 +609,7 @@ | |
| pub(crate) filter: PathFilter<'a>, | ||
| pub(crate) keep_options: KeepOptions, | ||
| pub(crate) pathname_editor: PathnameEditor, | ||
| pub(crate) ordered_path_locks: Arc<OrderedPathLocks>, | ||
|
Check warning on line 612 in cli/src/command/extract.rs
|
||
| pub(crate) unlink_first: bool, | ||
| pub(crate) time_filters: TimeFilters, | ||
| pub(crate) safe_writes: bool, | ||
|
|
@@ -1353,11 +1353,12 @@ | |
| return Ok(()); | ||
| }; | ||
|
|
||
| let mut read_options = ReadOptions::with_password(password); | ||
| if *safe_writes { | ||
| let mut safe_writer = SafeWriter::new(&path)?; | ||
| { | ||
| let mut writer = io::BufWriter::with_capacity(64 * 1024, safe_writer.as_file_mut()); | ||
| let mut reader = item.reader(ReadOptions::with_password(password))?; | ||
| let mut reader = item.reader(&mut read_options)?; | ||
| io::copy(&mut reader, &mut writer)?; | ||
| writer.flush()?; | ||
| } | ||
|
|
@@ -1369,7 +1370,7 @@ | |
| } | ||
| let file = utils::fs::file_create(&path, remove_existing)?; | ||
| let mut writer = io::BufWriter::with_capacity(64 * 1024, file); | ||
| let mut reader = item.reader(ReadOptions::with_password(password))?; | ||
| let mut reader = item.reader(&mut read_options)?; | ||
| io::copy(&mut reader, &mut writer)?; | ||
| let mut file = writer.into_inner().map_err(|e| e.into_error())?; | ||
| restore_timestamps(&mut file, item.metadata(), keep_options)?; | ||
|
|
@@ -1418,9 +1419,10 @@ | |
| return Ok(()); | ||
| }; | ||
|
|
||
| let mut read_options = ReadOptions::with_password(password); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instantiating |
||
| match item.header().data_kind() { | ||
| DataKind::SymbolicLink => { | ||
| let reader = item.reader(ReadOptions::with_password(password))?; | ||
| let reader = item.reader(&mut read_options)?; | ||
| let original = io::read_to_string(reader)?; | ||
| let original = pathname_editor.edit_symlink(original.as_ref()); | ||
| if !allow_unsafe_links && is_unsafe_link(&original) { | ||
|
|
@@ -1436,7 +1438,7 @@ | |
| symlink_with_type(&original, &path, link_target_type)?; | ||
| } | ||
| DataKind::HardLink => { | ||
| let reader = item.reader(ReadOptions::with_password(password))?; | ||
| let reader = item.reader(&mut read_options)?; | ||
| let original = io::read_to_string(reader)?; | ||
| let Some((original, had_root)) = pathname_editor.edit_hardlink(original.as_ref()) | ||
| else { | ||
|
|
@@ -1625,7 +1627,7 @@ | |
| MacMetadataStrategy::Always | ||
| ) && item.mac_metadata().is_some(); | ||
| #[cfg(not(target_os = "macos"))] | ||
| let skip_xattr_acl = false; | ||
|
Check warning on line 1630 in cli/src/command/extract.rs
|
||
|
|
||
| #[cfg(unix)] | ||
| if !skip_xattr_acl && matches!(keep_options.xattr_strategy, XattrStrategy::Always) { | ||
|
|
@@ -1881,7 +1883,8 @@ | |
| return Ok(()); | ||
| } | ||
|
|
||
| let mut reader = item.reader(ReadOptions::with_password(password))?; | ||
| let mut read_options = ReadOptions::with_password(password); | ||
| let mut reader = item.reader(&mut read_options)?; | ||
| let mut stdout = io::stdout().lock(); | ||
| io::copy(&mut reader, &mut stdout)?; | ||
| stdout.flush()?; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,7 +433,7 @@ impl TableRow { | |
| // Only read link target if needed (requires decompression) | ||
| if collect.link_target { | ||
| entry | ||
| .reader(ReadOptions::with_password(password)) | ||
| .reader(&mut ReadOptions::with_password(password)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .and_then(io::read_to_string) | ||
| .unwrap_or_else(|_| "-".into()) | ||
| } else { | ||
|
|
@@ -445,7 +445,7 @@ impl TableRow { | |
| // Only read link target if needed (requires decompression) | ||
| if collect.link_target { | ||
| entry | ||
| .reader(ReadOptions::with_password(password)) | ||
| .reader(&mut ReadOptions::with_password(password)) | ||
| .and_then(io::read_to_string) | ||
| .unwrap_or_else(|_| "-".into()) | ||
| } else { | ||
|
|
@@ -559,12 +559,13 @@ fn list_archive(ctx: &crate::cli::GlobalContext, args: ListCommand) -> anyhow::R | |
| let password = password.as_deref(); | ||
| let mut entries = Vec::new(); | ||
| let collect_opts = CollectOptions::from_list_options(&options); | ||
| let mut read_options = ReadOptions::with_password(password); | ||
| source.for_each_read_entry( | ||
| #[hooq::skip_all] | ||
| |entry| { | ||
| match entry? { | ||
| ReadEntry::Solid(solid) if options.solid => { | ||
| for entry in solid.entries(password)? { | ||
| for entry in solid.entries(&mut read_options)? { | ||
| entries.push(TableRow::from_entry( | ||
| &entry?, | ||
| password, | ||
|
|
@@ -646,14 +647,16 @@ pub(crate) fn run_list_archive<'a>( | |
| ) -> anyhow::Result<()> { | ||
| let collect_opts = CollectOptions::from_list_options(&args); | ||
|
|
||
| let mut read_options = ReadOptions::with_password(password); | ||
|
|
||
| if !fast_read || files_globs.is_empty() { | ||
| let mut entries = Vec::new(); | ||
| run_read_entries( | ||
| archive_provider, | ||
| |entry| { | ||
| match entry? { | ||
| ReadEntry::Solid(solid) if args.solid => { | ||
| for entry in solid.entries(password)? { | ||
| for entry in solid.entries(&mut read_options)? { | ||
| entries.push(TableRow::from_entry( | ||
| &entry?, | ||
| password, | ||
|
|
@@ -686,7 +689,7 @@ pub(crate) fn run_list_archive<'a>( | |
| |entry| { | ||
| match entry? { | ||
| ReadEntry::Solid(solid) if args.solid => { | ||
| for entry in solid.entries(password)? { | ||
| for entry in solid.entries(&mut read_options)? { | ||
| let entry = entry?; | ||
| let entry_path = entry.name().to_string(); | ||
| if !globs.matches_any_pattern(&entry_path) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reuse one
ReadOptionsacross solid transforms.These branches still create a fresh
ReadOptionsperReadEntry::Solid, so unsolid/keep-solid rewrites lose the newKeyCachebetween solid blocks and re-run the KDF for every block. Thread a shared&mut ReadOptionsfromrun_transform_entry()intoTransformStrategy::transform()instead of rebuilding it here.♻️ Minimal sketch
trait TransformStrategy { - fn transform<W, T, F>(archive: &mut Archive<W>, password: Option<&[u8]>, read_entry: io::Result<ReadEntry<T>>, transformer: F) -> io::Result<()> + fn transform<W, T, F>(archive: &mut Archive<W>, read_options: &mut ReadOptions, read_entry: io::Result<ReadEntry<T>>, transformer: F) -> io::Result<()> } ... - let password = password_provider(); + let mut read_options = ReadOptions::with_password(password_provider()); ... - |entry| Transform::transform(&mut out_archive, password, entry, &mut processor), + |entry| Transform::transform(&mut out_archive, &mut read_options, entry, &mut processor),Also applies to: 1236-1237
🤖 Prompt for AI Agents