diem_secure_storage/
lib.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8#![forbid(unsafe_code)]
9
10mod crypto_kv_storage;
11mod crypto_storage;
12mod error;
13mod in_memory;
14mod kv_storage;
15mod namespaced_storage;
16mod on_disk;
17mod policy;
18mod storage;
19
20pub use crate::{
21    crypto_kv_storage::CryptoKVStorage,
22    crypto_storage::{CryptoStorage, PublicKeyResponse},
23    error::Error,
24    in_memory::InMemoryStorage,
25    kv_storage::{GetResponse, KVStorage},
26    namespaced_storage::NamespacedStorage,
27    on_disk::OnDiskStorage,
28    policy::{Capability, Identity, Permission, Policy},
29    storage::Storage,
30};
31
32// Some common serializations for interacting with bytes these must be manually
33// added to types via: #[serde(serialize_with = "to_base64", deserialize_with =
34// "from_base64")] some_value: Vec<u8>
35
36pub fn to_base64<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
37where S: serde::Serializer {
38    serializer.serialize_str(&base64::encode(bytes))
39}
40
41pub fn from_base64<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
42where D: serde::Deserializer<'de> {
43    let s: String = serde::Deserialize::deserialize(deserializer)?;
44    base64::decode(s).map_err(serde::de::Error::custom)
45}
46
47#[cfg(test)]
48mod tests;