libfw_core/lib.rs
1//! Shared data structures, traits, protocol constants and streaming
2//! compression abstractions for the libfw transfer library.
3//!
4//! `libfw-core` is the foundation crate consumed by both
5//! [`libfw-server`](https://docs.rs/libfw-server) (server routing /
6//! middleware) and [`libfw-client`](https://docs.rs/libfw-client) (WASM
7//! engine + JS SDK). It contains no I/O of its own: it defines the *contracts*.
8//!
9//! # Highlights
10//!
11//! - [`TokenClaims`], [`Action`] and the [`Validator`] trait for
12//! fine-grained bearer-token authorization.
13//! - [`StorageBackend`] and [`UploadSink`] traits for pluggable storage.
14//! - [`Compressor`] / [`Decompressor`] streaming traits backed by
15//! [`zrip`] (zstd) with constant-memory guarantees.
16//! - Protocol constants: [`CHUNK_SIZE`], [`HEADER_COMPRESS`],
17//! [`HEADER_FILE_META`] and friends.
18//! - Transfer metadata ([`FileMeta`], [`TransferPlan`], [`ChunkMeta`]).
19//!
20//! # Example
21//!
22//! ```no_run
23//! use libfw_core::auth::{Action, PathValidator, Validator};
24//! use libfw_core::claims::{TokenClaims, Permission};
25//!
26//! let claims = TokenClaims {
27//! sub: "user-42".into(),
28//! exp: None,
29//! permissions: vec![Permission::Read, Permission::Write],
30//! allowed_paths: vec!["/docs/".into()],
31//! };
32//! let validator = PathValidator::new();
33//! assert!(validator.validate(&claims, "/docs/spec.pdf", Action::Read).is_ok());
34//! ```
35
36pub mod auth;
37pub mod capabilities;
38pub mod claims;
39pub mod compress;
40pub mod constants;
41pub mod error;
42pub mod metadata;
43pub mod pathmap;
44pub mod range;
45pub mod storage;
46
47pub use auth::{Action, AuthError, PathValidator, TokenVerifier, Validator};
48pub use capabilities::{Capabilities, CompressionCaps, IntRange, Limits, ZripLevels};
49pub use claims::{Permission, TokenClaims};
50pub use compress::{
51 CompressionFormat, Compressor, Decompressor, ZRIP_DEFAULT_LEVEL, ZRIP_MAX_LEVEL,
52 ZRIP_MIN_LEVEL, compressor_with_level, is_valid_zrip_level, negotiate_level,
53};
54pub use constants::*;
55pub use error::{CompressError, DecompressError, StorageError};
56pub use metadata::{ChunkMeta, FileMeta, TransferPlan};
57pub use pathmap::{IdentityPathCodec, MountPathCodec, PathCodec, PathCodecError};
58#[cfg(feature = "path-encrypt")]
59pub use pathmap::EncryptedPathCodec;
60pub use range::RangeSpec;
61pub use storage::{DirEntry, StorageBackend, UploadSink, WriteMode};