From: Ian Jackson Date: Sat, 14 May 2022 19:37:30 +0000 (+0100) Subject: support: Move digestrw and timedfd X-Git-Tag: otter-1.1.0~167 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=8e53784497ad230b421659a727f54879cac65e10;p=otter.git support: Move digestrw and timedfd Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index 735bead6..61e09673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2682,7 +2682,6 @@ dependencies = [ "const-default", "crossbeam-utils", "delegate", - "digest 0.10.3", "downcast-rs", "educe", "either", @@ -2698,7 +2697,6 @@ dependencies = [ "lazy-init", "lazy-regex", "libc", - "mio 0.8.2", "num", "num-traits", "once_cell", @@ -2709,7 +2707,6 @@ dependencies = [ "regex", "serde", "serde_with", - "sha2 0.10.2", "slotmap-fork-otter", "structopt", "strum", @@ -2822,11 +2819,13 @@ dependencies = [ "chrono-tz", "console", "derive-into-owned", + "digest 0.10.3", "fehler", "flexi_logger", "fs2", "lazy_static", "log", + "mio 0.8.2", "nix 0.23.1", "num-derive", "num-traits", @@ -2839,6 +2838,7 @@ dependencies = [ "rmp-serde", "serde", "serde_with", + "sha2 0.10.2", "strum", "toml", "unicode-width", diff --git a/Cargo.toml b/Cargo.toml index 0a04a824..b2d8854e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,6 @@ boolinator="2" cast_trait_object="0.1" crossbeam-utils="0.8" delegate="0.6" -digest="0.10" downcast-rs="1" educe="0.4" either="1" @@ -57,7 +56,6 @@ ordered-float="2" percent-encoding="2" regex="1" structopt="0.3" -sha2="0.10" subtle="2.4" tempfile="3" tera="1.10" @@ -76,7 +74,6 @@ const-default = { version="1", features=["derive" ] } enum-map = { version="2" , features=["serde" ] } image = { version = "0.24", default-features=false, features=["jpeg","png"] } index_vec = { version="0.1.1", features=["serde" ] } -mio = { version="0.8", features=["os-ext", "os-poll" ] } slotmap = { package="slotmap-fork-otter", version="1", git="https://github.com/ijackson/slotmap", branch="slotmap-fork-otter", features=["serde"] } diff --git a/src/bundles.rs b/src/bundles.rs index 40b70f27..089286f3 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -1374,3 +1374,18 @@ fn id_file_parse() { check_n("00000.xyz", "bad extension"); check_n("65536.zip", "bad index"); } + +#[test] +#[cfg(not(miri))] +fn test_digest_write() { + let ibuffer = b"xyz"; + let exp = Sha512_256::digest(&ibuffer[..]); + let mut obuffer = [0;4]; + let inner = &mut obuffer[..]; + let mut dw = bundles::DigestWrite::new(inner); + assert_eq!( dw.write(&ibuffer[..]).unwrap(), 3); + let (got, recov) = dw.finish(); + assert_eq!( recov, b"\0" ); + assert_eq!( got, exp ); + assert_eq!( &obuffer, b"xyz\0" ); +} diff --git a/src/crates.rs b/src/crates.rs index e670f638..c2b281b8 100644 --- a/src/crates.rs +++ b/src/crates.rs @@ -11,7 +11,6 @@ pub use base64; pub use boolinator; pub use cast_trait_object; pub use delegate; -pub use digest; pub use educe; pub use either; pub use env_logger; @@ -24,7 +23,6 @@ pub use libc; pub use once_cell; pub use ordered_float; pub use regex; -pub use sha2; pub use slotmap; pub use tera; pub use uds; diff --git a/src/imports.rs b/src/imports.rs index bf7b81be..969f7427 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -34,7 +34,6 @@ pub use boolinator::Boolinator as _; pub use cast_trait_object::{dyn_upcast, DynCastExt}; pub use const_default::ConstDefault; pub use delegate::delegate; -pub use digest::Digest; pub use downcast_rs::{impl_downcast, Downcast}; pub use educe::Educe; pub use either::{Either, Left, Right}; @@ -48,7 +47,6 @@ pub use percent_encoding::percent_decode_str; pub use percent_encoding::utf8_percent_encode; pub use percent_encoding::NON_ALPHANUMERIC; pub use regex::Regex; -pub use sha2::{Sha512, Sha512_256}; pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _}; pub use subtle::ConstantTimeEq; pub use tempfile::{self, NamedTempFile}; @@ -89,7 +87,6 @@ pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse}; pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode}; pub use crate::commands::{ProgressUpdateMode}; pub use crate::debugreader::DebugReader; -pub use crate::digestrw::{self, *}; pub use crate::error::*; pub use crate::fastsplit::*; pub use crate::gamestate::*; @@ -111,7 +108,6 @@ pub use crate::shapelib::{LibraryLoadError}; pub use crate::slotmap_slot_idx::*; pub use crate::spec::*; pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon}; -pub use crate::timedfd::*; pub use crate::updates::*; pub use crate::utils::*; pub use crate::ui::*; diff --git a/src/lib.rs b/src/lib.rs index d9dcc27d..f5840005 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,7 +30,6 @@ pub mod commands; pub mod currency; pub mod deck; pub mod dice; -pub mod digestrw; pub mod debugreader; pub mod error; pub mod fastsplit; @@ -48,7 +47,6 @@ pub mod pcrender; pub mod pieces; pub mod shapelib; pub mod spec; -pub mod timedfd; pub mod updates; pub mod ui; pub mod utils; diff --git a/support/Cargo.toml b/support/Cargo.toml index 70e7610e..020763da 100644 --- a/support/Cargo.toml +++ b/support/Cargo.toml @@ -32,6 +32,7 @@ chrono="0.4" chrono-tz="0.6" console="0.15" derive-into-owned="0.2" +digest="0.10" fehler="1" fs2="0.4" lazy_static="1" @@ -44,10 +45,12 @@ pwd="1" rand="0.8" rmp="0.8" rmp-serde="1" +sha2="0.10" toml="0.5" unicode-width="0.1" flexi_logger = { version="0.22" , features=["specfile" ] } +mio = { version="0.8", features=["os-ext", "os-poll" ] } # Repeated in other Cargo.toml's because importing does not work properly num-traits="0.2" diff --git a/support/crates.rs b/support/crates.rs index fc964f5f..32bcc0bf 100644 --- a/support/crates.rs +++ b/support/crates.rs @@ -9,6 +9,7 @@ pub use otter_base; pub use anyhow; pub use chrono; pub use chrono_tz; +pub use digest; pub use flexi_logger; pub use fs2; pub use lazy_static; @@ -18,5 +19,6 @@ pub use parking_lot; pub use pwd; pub use rand; pub use rmp_serde; +pub use sha2; pub use toml; pub use unicode_width; diff --git a/src/digestrw.rs b/support/digestrw.rs similarity index 82% rename from src/digestrw.rs rename to support/digestrw.rs index 08037393..1b658b04 100644 --- a/src/digestrw.rs +++ b/support/digestrw.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -use crate::crates::*; use crate::prelude::*; #[derive(Debug,Copy,Clone)] @@ -76,18 +75,3 @@ impl Write for DigestWrite { #[throws(io::Error)] fn flush(&mut self) { self.w.flush()? } } - -#[test] -#[cfg(not(miri))] -fn test_digest_write() { - let ibuffer = b"xyz"; - let exp = Sha512_256::digest(&ibuffer[..]); - let mut obuffer = [0;4]; - let inner = &mut obuffer[..]; - let mut dw = bundles::DigestWrite::new(inner); - assert_eq!( dw.write(&ibuffer[..]).unwrap(), 3); - let (got, recov) = dw.finish(); - assert_eq!( recov, b"\0" ); - assert_eq!( got, exp ); - assert_eq!( &obuffer, b"xyz\0" ); -} diff --git a/support/imports.rs b/support/imports.rs index 17df3a63..00198bba 100644 --- a/support/imports.rs +++ b/support/imports.rs @@ -32,6 +32,7 @@ pub use std::time::{self, Duration, Instant}; pub use anyhow::{anyhow, ensure, Context}; pub use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt}; pub use derive_into_owned::IntoOwned; +pub use digest::Digest; pub use flexi_logger::LogSpecification; pub use fs2::FileExt; pub use lazy_static::lazy_static; @@ -53,6 +54,7 @@ pub use serde::de::Error as _; pub use serde::{Deserializer, Serializer}; pub use serde_with::DeserializeFromStr; pub use serde_with::SerializeDisplay; +pub use sha2::{Sha512, Sha512_256}; pub use strum::{EnumCount, EnumDiscriminants}; pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; pub use strum::{AsRefStr, IntoEnumIterator, IntoStaticStr}; @@ -72,6 +74,7 @@ pub use crate::authproofs::AuthorisationSuperuser; pub use crate::childio; pub use crate::config::*; pub use crate::debugmutex::DebugIdentify; +pub use crate::digestrw::{self, *}; pub use crate::fake_rng::*; pub use crate::fake_time::*; pub use crate::packetframe::{FrameReader, FrameWriter, ReadFrame, WriteFrame}; @@ -80,6 +83,7 @@ pub use crate::packetframe::{PacketFrameReadError, PacketFrameWriteError}; pub use crate::progress::{self, ProgressInfo, OriginatorExt as _}; pub use crate::support::*; pub use crate::termprogress; +pub use crate::timedfd::*; pub use crate::toml_de; pub use crate::tz::*; diff --git a/support/lib.rs b/support/lib.rs index 17e2627b..c85885c1 100644 --- a/support/lib.rs +++ b/support/lib.rs @@ -10,10 +10,12 @@ pub mod authproofs; pub mod childio; pub mod config; pub mod debugmutex; +pub mod digestrw; pub mod packetframe; pub mod progress; pub mod support; pub mod termprogress; +pub mod timedfd; pub mod tz; #[path = "fake-rng.rs"] pub mod fake_rng; diff --git a/src/timedfd.rs b/support/timedfd.rs similarity index 100% rename from src/timedfd.rs rename to support/timedfd.rs