keeper_secrets_manager_core/lib.rs
1// -*- coding: utf-8 -*-
2// _ __
3// | |/ /___ ___ _ __ ___ _ _ (R)
4// | ' </ -_) -_) '_ \/ -_) '_|
5// |_|\_\___\___| .__/\___|_|
6// |_|
7//
8// Keeper Secrets Manager
9// Copyright 2024 Keeper Security Inc.
10// Contact: sm@keepersecurity.com
11//
12
13//! # Keeper Secrets Manager Rust SDK
14//!
15//! Type-safe, zero-knowledge client library for accessing secrets stored in Keeper's vault.
16//!
17//! ## Features
18//!
19//! - **Type-Safe API** - Leverages Rust's type system for compile-time safety
20//! - **Never Panics** - All operations return `Result<T, KSMRError>` with comprehensive error handling
21//! - **Multiple Storage Options** - File-based, in-memory, and caching support
22//! - **Zero-Knowledge Architecture** - All encryption/decryption happens client-side
23//! - **Keeper Notation** - URI-based field access (`keeper://UID/field/password`)
24//! - **Password Rotation** - Transaction-based rotation with commit/rollback
25//! - **GraphSync Support** - Linked record retrieval for managing relationships
26//! - **Disaster Recovery Caching** - Automatic fallback to cached data on network failures
27//!
28//! ## Quick Start
29//!
30//! ```no_run
31//! use keeper_secrets_manager_core::{SecretsManager, ClientOptions, KSMRError, KvStoreType, FileKeyValueStorage};
32//!
33//! fn main() -> Result<(), KSMRError> {
34//! // Initialize with one-time token
35//! let storage = FileKeyValueStorage::new(Some("config.json".to_string()))?;
36//! let config = KvStoreType::File(storage);
37//! let token = "US:YOUR_ONE_TIME_TOKEN".to_string();
38//! let options = ClientOptions::new_client_options_with_token(token, config);
39//! let mut secrets_manager = SecretsManager::new(options)?;
40//!
41//! // Retrieve secrets
42//! let secrets = secrets_manager.get_secrets(Vec::new())?;
43//! for secret in secrets {
44//! println!("Title: {}", secret.title);
45//! }
46//!
47//! Ok(())
48//! }
49//! ```
50//!
51//! Or use the builder:
52//!
53//! ```no_run
54//! use keeper_secrets_manager_core::{SecretsManager, ClientOptionsBuilder, KSMRError, KvStoreType, InMemoryKeyValueStorage};
55//!
56//! fn main() -> Result<(), KSMRError> {
57//! let config_b64 = std::env::var("KSM_CONFIG").expect("KSM_CONFIG required");
58//! let storage = InMemoryKeyValueStorage::new(Some(config_b64))?;
59//! let options = ClientOptionsBuilder::new(KvStoreType::InMemory(storage))
60//! .token("US:YOUR_ONE_TIME_TOKEN")
61//! .build();
62//! let mut sm = SecretsManager::new(options)?;
63//! let secrets = sm.get_secrets(Vec::new())?;
64//! println!("Found {} secrets", secrets.len());
65//! Ok(())
66//! }
67//! ```
68//!
69//! ## Modules
70//!
71//! - [`core`] - Main `SecretsManager` API and client configuration
72//! - [`storage`] - Storage backends (File, InMemory)
73//! - [`cache`] - Performance caching layer
74//! - [`caching`] - Disaster recovery caching with network fallback
75//! - [`crypto`] - Cryptographic operations (AES-GCM, ECDH, ECDSA)
76//! - [`dto`] - Data transfer objects (Record, Folder, File, Payload types)
77//! - [`utils`] - Utilities (password generation, TOTP, Base64 encoding)
78//! - [`custom_error`] - Error types (`KSMRError` enum)
79//! - [`enums`] - Type enums (field types, record types, storage types)
80//!
81//! ## Cargo Features
82//!
83//! | Feature | Default | Description |
84//! |---------|---------|-------------|
85//! | `blocking` | yes | Enables `reqwest/blocking` HTTP client |
86//! | `totp` | yes | TOTP code generation (`get_totp_code`) |
87//! | `password-gen` | yes | Password generation (`generate_password`) |
88//! | `tracing-init` | yes | `env_logger` initializer in the binary |
89
90pub mod cache;
91pub mod caching;
92pub mod config_keys;
93pub mod constants;
94pub mod core;
95pub mod crypto;
96pub mod custom_error;
97pub mod dto;
98pub mod enums;
99mod helpers;
100pub mod keeper_globals;
101pub mod storage;
102mod tests;
103pub mod utils;
104
105// --- Flat re-exports for ergonomic top-level imports ---
106
107pub use cache::KSMCache;
108pub use core::core::{ClientOptions, ClientOptionsBuilder, SecretsManager};
109pub use custom_error::KSMRError;
110pub use dto::dtos::{KeeperRecordLink, Record};
111pub use enums::{DefaultRecordType, KvStoreType, StandardFieldTypeEnum};
112pub use storage::{FileKeyValueStorage, InMemoryKeyValueStorage, KeyValueStorage};
113
114/// Convenient glob import for the most common types.
115///
116/// ```no_run
117/// use keeper_secrets_manager_core::prelude::*;
118/// ```
119pub mod prelude {
120 pub use crate::cache::KSMCache;
121 pub use crate::core::core::{ClientOptions, ClientOptionsBuilder, SecretsManager};
122 pub use crate::custom_error::KSMRError;
123 pub use crate::dto::dtos::{KeeperRecordLink, Record};
124 pub use crate::enums::{DefaultRecordType, KvStoreType, StandardFieldTypeEnum};
125 pub use crate::storage::{FileKeyValueStorage, InMemoryKeyValueStorage, KeyValueStorage};
126}