From: Ben Pfaff Date: Sun, 21 Dec 2025 01:11:13 +0000 (-0800) Subject: work X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5057c3d54ef98e62a6fc387c70d025bc79394eb5;p=pspp work --- diff --git a/rust/doc/src/spv/light-detail.md b/rust/doc/src/spv/light-detail.md index 0cb3253564..554a9b83ef 100644 --- a/rust/doc/src/spv/light-detail.md +++ b/rust/doc/src/spv/light-detail.md @@ -522,7 +522,7 @@ this field by default contains 1948. In the corpus, `epoch` ranges from 1943 to 1948, plus some contain -1. `decimal` is the decimal point character. The observed values are -`.` and `,`. +`.`, `,`, and 0. `grouping` is the grouping character. Usually, it is `,` if `decimal` is `.`, and vice versa. Other observed values are `'` @@ -532,7 +532,7 @@ should not be grouped). `n-ccs` is observed as either 0 or 5. When it is 5, the following strings are [CCA through CCE](../language/datasets/formats/custom-currency.md) format strings. -Most commonly these are all `-,,,` but other strings occur. +Most commonly these are all empty or `-,,,`, but other strings occur. A writer may safely use false for `x7`, `x8`, and `x9`. diff --git a/rust/pspp/src/cli/convert.rs b/rust/pspp/src/cli/convert.rs index e124c3bbc7..ae414aeb16 100644 --- a/rust/pspp/src/cli/convert.rs +++ b/rust/pspp/src/cli/convert.rs @@ -146,7 +146,7 @@ impl Convert { let (items, page_setup) = pspp::spv::ReadOptions::new(|e| eprintln!("{e}")) .with_password(self.password.clone()) .open_file(&self.input)? - .into_parts(); + .into_contents(); let mut output = self.open_driver("text")?; if let Some(page_setup) = &page_setup { output.setup(page_setup); diff --git a/rust/pspp/src/cli/decrypt.rs b/rust/pspp/src/cli/decrypt.rs index 50e0629cae..2765855a13 100644 --- a/rust/pspp/src/cli/decrypt.rs +++ b/rust/pspp/src/cli/decrypt.rs @@ -46,7 +46,7 @@ impl Decrypt { readpass::from_tty().unwrap() } }; - let mut reader = match input.unlock(password.as_bytes()) { + let mut reader = match input.unlock(password) { Ok(reader) => reader, Err(_) => return Err(anyhow!("Incorrect password.")), }; diff --git a/rust/pspp/src/cli/show_spv.rs b/rust/pspp/src/cli/show_spv.rs index 547aed110f..03acc6c0d4 100644 --- a/rust/pspp/src/cli/show_spv.rs +++ b/rust/pspp/src/cli/show_spv.rs @@ -65,6 +65,9 @@ enum Mode { /// Reads `.tlo` or `.stt` TableLook and outputs as `.stt` format. ConvertTableLook, + /// Print data values in legacy tables. + LegacyData, + /// Prints contents. View, } @@ -75,6 +78,7 @@ impl Mode { Mode::Directory => "directory", Mode::GetTableLook => "get-table-look", Mode::ConvertTableLook => "convert-table-look", + Mode::LegacyData => "legacy-data", Mode::View => "view", } } @@ -111,6 +115,15 @@ impl ShowSpv { } Ok(()) } + Mode::LegacyData => { + let item = pspp::spv::ReadOptions::new(|e| eprintln!("{e}")) + .with_password(self.password) + .open_file(&self.input)? + .into_items(); + let items = self.criteria.apply(item); + for child in items {} + todo!() + } Mode::GetTableLook => todo!(), Mode::ConvertTableLook => todo!(), } diff --git a/rust/pspp/src/crypto.rs b/rust/pspp/src/crypto.rs index cce9825632..ac7a2c4aec 100644 --- a/rust/pspp/src/crypto.rs +++ b/rust/pspp/src/crypto.rs @@ -16,37 +16,35 @@ use aes::{ cipher::{BlockDecrypt, KeyInit, generic_array::GenericArray}, }; use cmac::{Cmac, Mac}; +use displaydoc::Display; use smallvec::SmallVec; use std::{ fmt::Debug, io::{BufRead, Error as IoError, ErrorKind, Read, Seek, SeekFrom}, }; -use thiserror::Error as ThisError; use binrw::{BinRead, io::NoSeek}; /// Error reading an encrypted file. -#[derive(Clone, Debug, ThisError)] +#[derive(Clone, Debug, thiserror::Error, Display)] pub enum Error { - /// I/O error. - #[error("I/O error reading encrypted file wrapper ({0})")] + /// I/O error reading encrypted file wrapper ({0}). IoError(ErrorKind), /// Invalid padding in final encrypted data block. - #[error("Invalid padding in final encrypted data block")] InvalidPadding, /// Not an encrypted file. - #[error("Not an encrypted file")] NotEncrypted, - /// Encrypted file has invalid length. - #[error("Encrypted file has invalid length {0} (expected 4 more than a multiple of 16).")] + /// Encrypted file has invalid length {0} (expected 4 more than a multiple of 16). InvalidLength(u64), - /// Unknown file type. - #[error("Unknown file type {0:?}.")] + /// Unknown file type {0:?}. UnknownFileType(String), + + /// Incorrect password. + WrongPassword, } impl From for Error { @@ -69,6 +67,7 @@ struct EncryptedHeader { } /// An encrypted file. +#[derive(Clone)] pub struct EncryptedFile { reader: R, file_type: FileType, @@ -155,7 +154,11 @@ where /// `password` decoded with [EncodedPassword::decode]. If successful, /// returns an [EncryptedReader] for the file; on failure, returns the /// [EncryptedFile] again for another try. - pub fn unlock(self, password: &[u8]) -> Result, Self> { + pub fn unlock

(self, password: P) -> Result, Self> + where + P: AsRef<[u8]>, + { + let password = password.as_ref(); self.unlock_literal(password).or_else(|this| { match EncodedPassword::from_encoded(password) { Some(encoded) => this.unlock_literal(&encoded.decode()), @@ -170,7 +173,10 @@ where /// /// If the password itself might be encoded ("encrypted"), instead use /// [Self::unlock] to try it both ways. - pub fn unlock_literal(self, password: &[u8]) -> Result, Self> { + pub fn unlock_literal

(self, password: P) -> Result, Self> + where + P: AsRef<[u8]>, + { // NIST SP 800-108 fixed data. #[rustfmt::skip] static FIXED: &[u8] = &[ @@ -197,6 +203,7 @@ where ]; // Truncate password to at most 10 bytes. + let password = password.as_ref(); let password = password.get(..10).unwrap_or(password); let n = password.len(); @@ -265,10 +272,7 @@ fn parse_padding(block: &[u8; 16]) -> Option { } } -impl Debug for EncryptedFile -where - R: Read, -{ +impl Debug for EncryptedFile { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "EncryptedFile({:?})", &self.file_type) } @@ -276,8 +280,7 @@ where /// Encrypted file reader. /// -/// This implements [Read] and [Seek] for SPSS encrypted files. To construct an -/// [EncryptedReader], call [EncryptedFile::new], then [EncryptedFile::unlock]. +/// This implements [Read] and [Seek] for SPSS encrypted files. pub struct EncryptedReader { /// Underlying reader. reader: R, @@ -305,7 +308,26 @@ pub struct EncryptedReader { tail: usize, } +/// The [Read] and [Seek] traits together, for use as `dyn ReadSeek`. +pub trait ReadSeek: Read + Seek {} +impl ReadSeek for T where T: Read + Seek {} + impl EncryptedReader { + /// Opens `reader` and unlocks it with the given password in one step. + /// + /// This fails if the password is wrong. To allow for multiple password + /// tries, use [EncryptedFile::new] followed by [EncryptedFile::unlock] + /// instead. + pub fn open

(reader: R, password: P) -> Result + where + R: Read + Seek, + P: AsRef<[u8]>, + { + EncryptedFile::new(reader)? + .unlock(password) + .map_err(|_| Error::WrongPassword) + } + fn new(reader: R, aes: Aes256Dec, file_type: FileType, length: u64) -> Self { Self { reader, @@ -515,7 +537,11 @@ pub struct EncodedPassword(Vec>); impl EncodedPassword { /// Creates an [EncodedPassword] from an already-encoded password `encoded`. /// Returns `None` if `encoded` is not a valid encoded password. - pub fn from_encoded(encoded: &[u8]) -> Option { + pub fn from_encoded

(encoded: P) -> Option + where + P: AsRef<[u8]>, + { + let encoded = encoded.as_ref(); if encoded.len() > 20 || encoded.len() % 2 != 0 || !encoded.iter().all(|byte| (32..=127).contains(byte)) @@ -531,7 +557,8 @@ impl EncodedPassword { /// Returns an [EncodedPassword] as an encoded version of the given /// `plaintext` password. Only the first 10 bytes, at most, of the /// plaintext password is used. - pub fn from_plaintext(plaintext: &[u8]) -> EncodedPassword { + pub fn from_plaintext>(plaintext: P) -> EncodedPassword { + let plaintext = plaintext.as_ref(); let input = plaintext.get(..10).unwrap_or(plaintext); EncodedPassword( input @@ -592,7 +619,7 @@ mod tests { let mut cursor = Cursor::new(&input); let file = EncryptedFile::new(&mut cursor).unwrap(); assert_eq!(file.file_type(), file_type); - let mut reader = file.unlock_literal(password.as_bytes()).unwrap(); + let mut reader = file.unlock_literal(password).unwrap(); assert_eq!(reader.file_type(), file_type); let mut actual = Vec::new(); std::io::copy(&mut reader, &mut actual).unwrap(); @@ -658,7 +685,7 @@ mod tests { let encoded = EncodedPassword::from_plaintext(&[plaintext]); for variant in 0..encoded.n_variants() { let encoded_variant = encoded.variant(variant); - let decoded = EncodedPassword::from_encoded(encoded_variant.as_bytes()) + let decoded = EncodedPassword::from_encoded(encoded_variant) .unwrap() .decode(); assert_eq!(&[plaintext], decoded.as_slice()); diff --git a/rust/pspp/src/output/drivers/cairo/driver.rs b/rust/pspp/src/output/drivers/cairo/driver.rs index 14cf853d9a..fe783a0b04 100644 --- a/rust/pspp/src/output/drivers/cairo/driver.rs +++ b/rust/pspp/src/output/drivers/cairo/driver.rs @@ -29,7 +29,7 @@ use serde::{Deserialize, Serialize}; use crate::{ output::{ - Details, Item, ItemCursor, TextType, + Item, ItemCursor, TextType, drivers::{ Driver, cairo::{ diff --git a/rust/pspp/src/output/pivot/testdata/d2_cl-all_layers.expected b/rust/pspp/src/output/pivot/testdata/d2_cl-all_layers.expected index cdb9255969..842bf2702a 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_cl-all_layers.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_cl-all_layers.expected @@ -1,5 +1,5 @@ Column (All Layers) -b1 +b: b1 ╭──┬──┬──╮ │a1│a2│a3│ ├──┼──┼──┤ @@ -7,7 +7,7 @@ b1 ╰──┴──┴──╯ Column (All Layers) -b2 +b: b2 ╭──┬──┬──╮ │a1│a2│a3│ ├──┼──┼──┤ @@ -15,7 +15,7 @@ b2 ╰──┴──┴──╯ Column (All Layers) -b3 +b: b3 ╭──┬──┬──╮ │a1│a2│a3│ ├──┼──┼──┤ diff --git a/rust/pspp/src/output/pivot/testdata/d2_cl-layer0.expected b/rust/pspp/src/output/pivot/testdata/d2_cl-layer0.expected index 48a28c4991..9a3c09891e 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_cl-layer0.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_cl-layer0.expected @@ -1,5 +1,5 @@ Column x b1 -b1 +b: b1 ╭──┬──┬──╮ │a1│a2│a3│ ├──┼──┼──┤ diff --git a/rust/pspp/src/output/pivot/testdata/d2_cl-layer1.expected b/rust/pspp/src/output/pivot/testdata/d2_cl-layer1.expected index 9e9323c810..6611a174d5 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_cl-layer1.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_cl-layer1.expected @@ -1,5 +1,5 @@ Column x b2 -b2 +b: b2 ╭──┬──┬──╮ │a1│a2│a3│ ├──┼──┼──┤ diff --git a/rust/pspp/src/output/pivot/testdata/d2_rl-all_layers.expected b/rust/pspp/src/output/pivot/testdata/d2_rl-all_layers.expected index 0aa4682594..2a83533b22 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_rl-all_layers.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_rl-all_layers.expected @@ -1,5 +1,5 @@ Row (All Layers) -b1 +b: b1 ╭──┬─╮ │a1│0│ │a2│1│ @@ -7,7 +7,7 @@ b1 ╰──┴─╯ Row (All Layers) -b2 +b: b2 ╭──┬─╮ │a1│3│ │a2│4│ @@ -15,7 +15,7 @@ b2 ╰──┴─╯ Row (All Layers) -b3 +b: b3 ╭──┬─╮ │a1│6│ │a2│7│ diff --git a/rust/pspp/src/output/pivot/testdata/d2_rl-layer0.expected b/rust/pspp/src/output/pivot/testdata/d2_rl-layer0.expected index 1f7667590a..843d15dbbc 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_rl-layer0.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_rl-layer0.expected @@ -1,5 +1,5 @@ Row x b1 -b1 +b: b1 ╭──┬─╮ │a1│0│ │a2│1│ diff --git a/rust/pspp/src/output/pivot/testdata/d2_rl-layer1.expected b/rust/pspp/src/output/pivot/testdata/d2_rl-layer1.expected index 051797d192..53ad394014 100644 --- a/rust/pspp/src/output/pivot/testdata/d2_rl-layer1.expected +++ b/rust/pspp/src/output/pivot/testdata/d2_rl-layer1.expected @@ -1,5 +1,5 @@ Row x b2 -b2 +b: b2 ╭──┬─╮ │a1│3│ │a2│4│ diff --git a/rust/pspp/src/output/pivot/testdata/d3-layer0_0.expected b/rust/pspp/src/output/pivot/testdata/d3-layer0_0.expected index c2eefe00c4..3ddf5ab679 100644 --- a/rust/pspp/src/output/pivot/testdata/d3-layer0_0.expected +++ b/rust/pspp/src/output/pivot/testdata/d3-layer0_0.expected @@ -1,6 +1,6 @@ Column x b1 x a1 -b1 -a1 +b: b1 +a: a1 ╭──┬──┬──┬──┬──╮ │c1│c2│c3│c4│c5│ ├──┼──┼──┼──┼──┤ diff --git a/rust/pspp/src/output/pivot/testdata/d3-layer0_1.expected b/rust/pspp/src/output/pivot/testdata/d3-layer0_1.expected index aaa4395528..8f4dd26678 100644 --- a/rust/pspp/src/output/pivot/testdata/d3-layer0_1.expected +++ b/rust/pspp/src/output/pivot/testdata/d3-layer0_1.expected @@ -1,6 +1,6 @@ Column x b2 x a1 -b2 -a1 +b: b2 +a: a1 ╭──┬──┬──┬──┬──╮ │c1│c2│c3│c4│c5│ ├──┼──┼──┼──┼──┤ diff --git a/rust/pspp/src/output/pivot/testdata/d3-layer1_2.expected b/rust/pspp/src/output/pivot/testdata/d3-layer1_2.expected index 55fb1525e2..bc679a3ebe 100644 --- a/rust/pspp/src/output/pivot/testdata/d3-layer1_2.expected +++ b/rust/pspp/src/output/pivot/testdata/d3-layer1_2.expected @@ -1,6 +1,6 @@ Column x b3 x a2 -b3 -a2 +b: b3 +a: a2 ╭──┬──┬──┬──┬──╮ │c1│c2│c3│c4│c5│ ├──┼──┼──┼──┼──┤ diff --git a/rust/pspp/src/spv/read.rs b/rust/pspp/src/spv/read.rs index 158e31c10b..611dd70ff2 100644 --- a/rust/pspp/src/spv/read.rs +++ b/rust/pspp/src/spv/read.rs @@ -23,7 +23,7 @@ use std::{ rc::Rc, }; -use anyhow::{Context, anyhow}; +use anyhow::Context; use binrw::{BinRead, error::ContextExt}; use cairo::ImageSurface; use displaydoc::Display; @@ -32,7 +32,7 @@ use serde::Deserialize; use zip::{ZipArchive, result::ZipError}; use crate::{ - crypto::EncryptedFile, + crypto::EncryptedReader, output::{ Details, Item, SpvInfo, SpvMembers, Text, page, pivot::{Axis2, Length, TableProperties, look::Look, value::Value}, @@ -109,64 +109,49 @@ impl ReadOptions { } } +pub trait ReadSeek: Read + Seek {} +impl ReadSeek for T where T: Read + Seek {} + impl ReadOptions where F: FnMut(Warning) + 'static, { /// Opens the file at `path`. - pub fn open_file

(mut self, path: P) -> Result + pub fn open_file

(self, path: P) -> Result where P: AsRef, { - let file = File::open(path)?; - if let Some(password) = self.password.take() { - self.open_reader_encrypted(file, password) - } else { - Self::open_reader_inner(file, self.warn) - } + self.open_reader(File::open(path)?) } /// Opens the file read from `reader`. - fn open_reader_encrypted(self, reader: R, password: String) -> Result + pub fn open_reader(self, reader: R) -> Result where R: Read + Seek + 'static, { - Self::open_reader_inner( - EncryptedFile::new(reader)? - .unlock(password.as_bytes()) - .map_err(|_| anyhow!("Incorrect password."))?, - self.warn, - ) + let reader = match &self.password { + None => Box::new(reader) as Box, + Some(password) => Box::new(EncryptedReader::open(reader, password)?), + }; + self.open_reader_inner(Box::new(reader)) } - /// Opens the file read from `reader`. - pub fn open_reader(mut self, reader: R) -> Result - where - R: Read + Seek + 'static, - { - if let Some(password) = self.password.take() { - self.open_reader_encrypted(reader, password) - } else { - Self::open_reader_inner(reader, self.warn) - } - } - - fn open_reader_inner(reader: R, warn: F) -> Result - where - R: Read + Seek + 'static, - { - // Open archive. - let mut archive = ZipArchive::new(reader).map_err(|error| match error { + fn open_reader_inner(self, reader: Box) -> Result { + let archive = ZipArchive::new(reader).map_err(|error| match error { ZipError::InvalidArchive(_) => Error::NotSpv, other => other.into(), })?; - Ok(Self::from_spv_zip_archive(&mut archive, warn)?) + Ok(self.open_zip_archive(archive)?) } - fn from_spv_zip_archive(archive: &mut ZipArchive, warn: F) -> Result - where - R: Read + Seek, - { + /// Opens the provided Zip `archive`. + /// + /// Any password provided for reading the file is unused, because if one was + /// needed then it must have already been used to open the archive. + pub fn open_zip_archive( + self, + mut archive: ZipArchive>, + ) -> Result { // Check manifest. let mut file = archive .by_name("META-INF/MANIFEST.MF") @@ -179,13 +164,13 @@ where drop(file); // Read all the items. - let warn = Rc::new(RefCell::new(Box::new(warn) as Box)); + let warn = Rc::new(RefCell::new(Box::new(self.warn) as Box)); let mut items = Vec::new(); let mut page_setup = None; for i in 0..archive.len() { let name = String::from(archive.name_for_index(i).unwrap()); if name.starts_with("outputViewer") && name.ends_with(".xml") { - let (mut new_items, ps) = read_heading(archive, i, &name, &warn)?; + let (mut new_items, ps) = read_heading(&mut archive, i, &name, &warn)?; items.append(&mut new_items); page_setup = page_setup.or(ps); } @@ -194,6 +179,7 @@ where Ok(SpvFile { items: items.into_iter().collect(), page_setup, + archive, }) } } @@ -205,11 +191,14 @@ pub struct SpvFile { /// The page setup in the SPV file, if any. pub page_setup: Option, + + /// The Zip archive that the file was read from. + pub archive: ZipArchive>, } impl SpvFile { - /// Returns the individual parts of the `SpvFile`. - pub fn into_parts(self) -> (Vec, Option) { + /// Returns the contents of the `SpvFile`. + pub fn into_contents(self) -> (Vec, Option) { (self.items, self.page_setup) } @@ -227,6 +216,9 @@ pub enum Error { /// Not an SPV file. NotSpv, + /// {0} + EncryptionError(#[from] crate::crypto::Error), + /// {0} ZipError(#[from] ZipError), diff --git a/rust/pspp/src/spv/read/html.rs b/rust/pspp/src/spv/read/html.rs index f334ecc95a..c4cb7ba7c4 100644 --- a/rust/pspp/src/spv/read/html.rs +++ b/rust/pspp/src/spv/read/html.rs @@ -284,7 +284,7 @@ impl Markup { .with_attribute(("color", color.display_css().to_string().as_str())), Style::Size(points) => writer .create_element("font") - .with_attribute(("size", format!("{points}pt").as_str())), + .with_attribute(("size", format!("{}pt", *points / 0.75).as_str())), } .write_inner_content(|w| child.write_html(w))?; } @@ -765,7 +765,7 @@ fn parse_nodes(nodes: &[Node]) -> Markup { && let Some(points) = [6.0, 7.5, 9.0, 10.5, 13.5, 18.0, 27.0].get(index).copied() { - apply_style(&mut inner, Style::Size(points)); + apply_style(&mut inner, Style::Size(points * 0.75)); } None } @@ -1007,7 +1007,7 @@ mod tests { let document = Document::from_html(&content); assert_eq!( document.to_html(), - r##"

&[PageTitle]

"## + r##"

&[PageTitle]

"## ); assert_eq!( document.0[0] @@ -1042,7 +1042,7 @@ mod tests { let html = Document::from_html(&content); assert_eq!( html.to_html(), - r##"

Page &[Page]

"## + r##"

Page &[Page]

"## ); } diff --git a/rust/pspp/src/spv/read/light.rs b/rust/pspp/src/spv/read/light.rs index 321255a997..251743e00b 100644 --- a/rust/pspp/src/spv/read/light.rs +++ b/rust/pspp/src/spv/read/light.rs @@ -1074,7 +1074,9 @@ impl Y0 { match Decimal::try_from(c) { Ok(decimal) => decimal, Err(_) => { - warn(LightWarning::InvalidDecimal(c)); + if c != '\0' { + warn(LightWarning::InvalidDecimal(c)); + } Decimal::default() } } @@ -1098,10 +1100,12 @@ impl CustomCurrency { let mut ccs = EnumMap::default(); for (cc, string) in enum_iterator::all().zip(&self.ccs) { let string = string.decode(encoding); - if let Ok(style) = NumberStyle::from_str(&string) { - ccs[cc] = Some(Box::new(style)); - } else { - warn(LightWarning::InvalidCustomCurrency(string)); + if !string.is_empty() { + if let Ok(style) = NumberStyle::from_str(&string) { + ccs[cc] = Some(Box::new(style)); + } else { + warn(LightWarning::InvalidCustomCurrency(string)); + } } } ccs diff --git a/rust/pspp/src/sys/cooked.rs b/rust/pspp/src/sys/cooked.rs index 2b39006329..cee6929d87 100644 --- a/rust/pspp/src/sys/cooked.rs +++ b/rust/pspp/src/sys/cooked.rs @@ -24,7 +24,7 @@ use std::{ }; use crate::{ - crypto::EncryptedFile, + crypto::EncryptedReader, data::{ByteString, Case, Datum, MutRawString, RawString}, dictionary::{ DictIndexMultipleResponseSet, DictIndexVariableSet, Dictionary, MrSetError, @@ -50,7 +50,7 @@ use crate::{ }, variable::{InvalidRole, MissingValues, MissingValuesError, VarType, VarWidth, Variable}, }; -use anyhow::{Error as AnyError, anyhow}; +use anyhow::Error as AnyError; use binrw::{BinRead, BinWrite, Endian}; use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; use encoding_rs::{Encoding, UTF_8}; @@ -542,9 +542,7 @@ impl ReadOptions { F: FnMut(AnyError), { Self::open_reader_inner( - EncryptedFile::new(reader)? - .unlock(password.as_bytes()) - .map_err(|_| anyhow!("Incorrect password."))?, + EncryptedReader::open(reader, password)?, self.encoding, self.warn, ) diff --git a/rust/pspp/src/sys/tests.rs b/rust/pspp/src/sys/tests.rs index 3e2afa3661..1fb63e4f9a 100644 --- a/rust/pspp/src/sys/tests.rs +++ b/rust/pspp/src/sys/tests.rs @@ -732,7 +732,7 @@ fn test_encrypted_sysfile(name: &str, password: &str) { .with_extension("sav"); let sysfile = EncryptedFile::new(File::open(&input_filename).unwrap()) .unwrap() - .unlock(password.as_bytes()) + .unlock(password) .unwrap(); let expected_filename = input_filename.with_extension("expected"); let expected = String::from_utf8(std::fs::read(&expected_filename).unwrap()).unwrap();