Skip to main content

hakanai_lib/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Zero-knowledge secret sharing client library for Hakanai.
4//!
5//! This library provides a complete client implementation for sending and receiving
6//! ephemeral secrets using the Hakanai service. All encryption and decryption
7//! happens client-side, ensuring the server never has access to plaintext data.
8//!
9//! # Architecture
10//!
11//! The library uses a layered client architecture:
12//! - `WebClient` - Handles HTTP communication
13//! - `CryptoClient` - Adds AES-256-GCM encryption/decryption
14//! - `SecretClient` - Handles `Payload` serialization/deserialization
15//!
16//! # Examples
17//!
18//! ## Basic Usage
19//!
20//! ```no_run
21//! use hakanai_lib::{client, client::Client};
22//! use std::time::Duration;
23//! use url::Url;
24//!
25//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
26//! // Create a client with the default configuration
27//! let client = client::new();
28//!
29//! // Send a text secret
30//! let secret_url = client.send_secret(
31//!     Url::parse("https://example.com")?,
32//!     hakanai_lib::models::Payload::from_bytes(b"My secret message"),
33//!     Duration::from_secs(3600), // 1 hour TTL
34//!     "auth-token".to_string(),
35//!     None, // No custom options
36//! ).await?;
37//!
38//! println!("Secret URL: {}", secret_url);
39//!
40//! // Receive the secret (normally done by recipient)
41//! let payload = client.receive_secret(secret_url, None).await?;
42//! println!("Retrieved: {:#?}", payload.data);
43//! # Ok(())
44//! # }
45//! ```
46//!
47//! ## Sending Binary Files
48//!
49//! ```no_run
50//! use hakanai_lib::{client, client::Client, models::Payload};
51//! use std::time::Duration;
52//! use url::Url;
53//!
54//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
55//! let client = client::new();
56//!
57//! // Read file and create payload
58//! let file_contents = std::fs::read("document.pdf")?;
59//! let payload = Payload::from_bytes(&file_contents).with_filename("document.pdf");
60//!
61//! // Send the file
62//! let secret_url = client.send_secret(
63//!     Url::parse("https://example.com")?,
64//!     payload,
65//!     Duration::from_secs(86400), // 24 hour TTL
66//!     "auth-token".to_string(),
67//!     None,
68//! ).await?;
69//!
70//! println!("File shared at: {}", secret_url);
71//! # Ok(())
72//! # }
73//! ```
74//!
75//! ## Using Progress Monitoring
76//!
77//! ```no_run
78//! use hakanai_lib::{client, client::Client, models::Payload, options::SecretSendOptions};
79//! use hakanai_lib::observer::DataTransferObserver;
80//! use std::sync::Arc;
81//! use std::time::Duration;
82//! use url::Url;
83//!
84//! struct ProgressReporter;
85//!
86//! #[async_trait::async_trait]
87//! impl DataTransferObserver for ProgressReporter {
88//!     async fn on_progress(&self, bytes_transferred: u64, total_bytes: u64) {
89//!         println!("Progress: {:.1}%", (bytes_transferred as f64 / total_bytes as f64) * 100.0);
90//!     }
91//! }
92//!
93//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
94//! let client = client::new();
95//! let options = SecretSendOptions::new().with_observer(Arc::new(ProgressReporter));
96//!
97//! client.send_secret(
98//!     Url::parse("https://example.com")?,
99//!     Payload::from_bytes(b"Secret data"),
100//!     Duration::from_secs(3600),
101//!     "auth-token".to_string(),
102//!     Some(options),
103//! ).await?;
104//! # Ok(())
105//! # }
106//! ```
107//!
108//!
109//!
110
111pub mod client;
112pub mod models;
113pub mod observer;
114pub mod options;
115pub mod utils;
116
117#[cfg(any(test, feature = "testing"))]
118pub mod client_mock;
119
120mod crypto;
121mod web;