mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:55:14 +00:00
craft-xls: the testing module is built only for tests and the test-support feature (#1377)
This commit is contained in:
1 parent
27fe59ab79
commit
4dc91cdaf8
5 files changed
+13
-1
No files matched your search
Generated
+1
@@ -3242,6 +3242,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"craft-cfb",
|
||||
"craft-sheet",
|
||||
"craft-xls",
|
||||
"md-5 0.10.6",
|
||||
"miniz_oxide 0.9.1",
|
||||
"sha1 0.10.7",
|
||||
|
||||
@@ -10,6 +10,10 @@ repository.workspace = true
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[features]
|
||||
# `testing`: a writer of small BIFF8 workbooks, plain or encrypted, for the tests of crates that read them.
|
||||
test-support = []
|
||||
|
||||
[dependencies]
|
||||
craft-cfb = { workspace = true }
|
||||
craft-sheet = { workspace = true }
|
||||
@@ -21,4 +25,5 @@ miniz_oxide = "0.9"
|
||||
thiserror = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
craft-xls = { path = ".", features = ["test-support"] }
|
||||
miniz_oxide = "0.9"
|
||||
@@ -63,7 +63,8 @@ with `read_with_password` ([MS-OFFCRYPTO] 2.3.5, 2.3.6). Without a password, Exc
|
||||
is `Error::WrongPassword`; XOR obfuscation and CryptoAPI with AES, another cipher or hash, or an
|
||||
external provider are `Error::UnsupportedEncryption`. Every size in the FilePass record is
|
||||
checked before it is used. There is no writer
|
||||
(`craft_xls::testing` builds small fixtures for tests).
|
||||
(`craft_xls::testing` builds small fixtures for tests; another crate's tests get it through the
|
||||
`test-support` feature).
|
||||
|
||||
A formula that cannot be put back into text (a link to another workbook, a macro command, an
|
||||
unknown token) leaves its cell with the saved result, and `Warning::FormulaKept` says why.
|
||||
|
||||
@@ -337,6 +337,7 @@ impl Rc4 {
|
||||
/// Encrypts a Workbook stream the way [`decrypt`] reads it, for tests: the FilePass record
|
||||
/// (RC4 1.1 with a fixed salt and verifier) goes right after the globals' BOF. `None` when the
|
||||
/// stream does not start with a record.
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub(crate) fn encrypt(stream: &[u8], password: &str) -> Option<Vec<u8>> {
|
||||
let salt: [u8; 16] = std::array::from_fn(|n| n as u8 + 0x40);
|
||||
let verifier: [u8; 16] = std::array::from_fn(|n| n as u8 + 0x60);
|
||||
@@ -359,6 +360,7 @@ pub(crate) fn encrypt(stream: &[u8], password: &str) -> Option<Vec<u8>> {
|
||||
|
||||
/// The FilePass data [`encrypt_cryptoapi`] writes: RC4 CryptoAPI version 4.2, as current Excel
|
||||
/// writes it, with a `bits`-bit key (40 to 128) and a fixed salt and verifier.
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub(crate) fn cryptoapi_filepass(password: &str, bits: u32) -> Vec<u8> {
|
||||
let salt: [u8; SALT_LEN] = std::array::from_fn(|n| (n as u8).wrapping_mul(7).wrapping_add(0x11));
|
||||
let verifier: [u8; SALT_LEN] = std::array::from_fn(|n| n as u8 + 0x80);
|
||||
@@ -381,12 +383,14 @@ pub(crate) fn cryptoapi_filepass(password: &str, bits: u32) -> Vec<u8> {
|
||||
}
|
||||
|
||||
/// [`encrypt`] with RC4 CryptoAPI ([`cryptoapi_filepass`]).
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
pub(crate) fn encrypt_cryptoapi(stream: &[u8], password: &str, bits: u32) -> Option<Vec<u8>> {
|
||||
with_filepass(stream, &cryptoapi_filepass(password, bits), password)
|
||||
}
|
||||
|
||||
/// `stream` with a FilePass record holding `filepass` right after its first BOF, encrypted with
|
||||
/// `password`.
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fn with_filepass(stream: &[u8], filepass: &[u8], password: &str) -> Option<Vec<u8>> {
|
||||
let (_, bof) = header(stream, 0)?;
|
||||
let bof_len = 4 + bof;
|
||||
|
||||
@@ -46,6 +46,7 @@ mod notes;
|
||||
mod read;
|
||||
mod records;
|
||||
mod styles;
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
#[doc(hidden)]
|
||||
pub mod testing;
|
||||
|
||||
|
||||
Reference in new issue
Block a user