pubnub/core/
crypto_provider.rs

1//! # Crypto provider module
2//!
3//! This module contains the [`CryptoProvider`] trait, which is used to
4//! implement a module that can be used to configure [`PubNubClientInstance`] or
5//! for manual data encryption and decryption.
6
7use crate::{
8    core::PubNubError,
9    lib::{alloc::vec::Vec, core::fmt::Debug},
10};
11
12/// Crypto provider trait.
13pub trait CryptoProvider: Debug + Send + Sync {
14    /// Encrypt provided data.
15    ///
16    /// # Errors
17    /// Should return an [`PubNubError::Encryption`] if provided data can't be
18    /// _encrypted_ or underlying cryptor misconfigured.
19    fn encrypt(&self, data: Vec<u8>) -> Result<Vec<u8>, PubNubError>;
20
21    /// Decrypt provided data.
22    ///
23    /// # Errors
24    /// Should return an [`PubNubError::Decryption`] if provided data can't be
25    /// _decrypted_ or underlying cryptor misconfigured.
26    fn decrypt(&self, data: Vec<u8>) -> Result<Vec<u8>, PubNubError>;
27}