sevola_encrypt/lib.rs
1//! Rust SDK for **Sevola Encrypt** — encryption and tokenization as a service
2//! by PT Ifabula Digital Kreasi.
3//!
4//! The SDK wraps the data-plane API (`x-api-key` auth) and offers two paths:
5//!
6//! | Path | Cipher | Use |
7//! |---|---|---|
8//! | **at rest** | FF1 format-preserving (radix 10 / 62) | field-level encryption that keeps the value's shape |
9//! | **in transit** | AES-256-CBC, key stretched with PBKDF2 | opaque payloads, optionally with a per-message key |
10//!
11//! ```no_run
12//! use sevola_encrypt::{EncryptClient, EncryptRequest, Template};
13//!
14//! # async fn demo() -> sevola_encrypt::Result<()> {
15//! let client = EncryptClient::new("your-api-key")?;
16//!
17//! // Format-preserving: a 16-digit card stays 16 digits.
18//! let results = client
19//! .encrypt_data(&[EncryptRequest {
20//! template: Template::Numeric,
21//! data: "4111111111111111".into(),
22//! }])
23//! .await?;
24//! println!("{:?}", results[0].value());
25//!
26//! // Transit: opaque base64.
27//! let sealed = client.encrypt_transit("nomor rekening: 1234567890").await?;
28//! let opened = client.decrypt_transit(&sealed).await?;
29//! # Ok(())
30//! # }
31//! ```
32//!
33//! # Compatibility
34//!
35//! Ciphertext must round-trip with the Java, JS, PHP, .NET and Go SDKs, so the
36//! algorithm details in [`crypto`], [`markers`] and [`pipeline`] are wire
37//! format, not implementation choices. They are pinned by golden vectors
38//! generated from the Go SDK — see `testdata/gen` and `tests/golden.rs`.
39//!
40//! # Feature flags
41//!
42//! * `client` *(default)* — the async HTTP client, [`EncryptClient`].
43//! Turn it off for a dependency-light crate with only the crypto and marker
44//! layer, which is what an FFI core or a wasm build wants.
45
46#![forbid(unsafe_code)]
47#![warn(missing_docs)]
48
49/// The README's examples are compiled as doctests so they cannot go stale.
50/// `cfg(doctest)` keeps the README itself out of the rendered documentation —
51/// this only exists to give `cargo test` something to check.
52#[doc = include_str!("../README.md")]
53#[cfg(doctest)]
54pub struct ReadmeExamples;
55
56pub mod crypto;
57pub mod error;
58pub mod markers;
59pub mod pipeline;
60pub mod types;
61
62#[cfg(feature = "client")]
63pub mod client;
64
65pub use error::{Error, Result};
66pub use types::{
67 ClientOptions, DecryptRequest, EncryptRequest, ItemResult, KeyType, Operation, Template,
68 TemplateProfile, DEFAULT_ALPHABET, DEFAULT_BASE_URL, NUMERIC_ALPHABET, TWEAK_B64,
69};
70
71#[cfg(feature = "client")]
72pub use client::EncryptClient;
73
74/// The fixed tweak, decoded. FF1 needs a tweak; Sevola uses one constant value
75/// across all SDKs so ciphertext is portable between them.
76pub fn tweak() -> Vec<u8> {
77 use base64::{engine::general_purpose::STANDARD, Engine as _};
78 STANDARD
79 .decode(TWEAK_B64)
80 .expect("TWEAK_B64 is a compile-time constant")
81}