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
10extern crate rand_08 as rand;
11
12mod crypto_kv_storage;
13mod crypto_storage;
14mod error;
15mod kv_storage;
16mod on_disk;
17
18pub use crate::{
19    crypto_kv_storage::CryptoKVStorage,
20    crypto_storage::{CryptoStorage, PublicKeyResponse},
21    error::Error,
22    kv_storage::{GetResponse, KVStorage},
23    on_disk::OnDiskStorage,
24};
25
26// Some common serializations for interacting with bytes these must be manually
27// added to types via: #[serde(serialize_with = "to_base64", deserialize_with =
28// "from_base64")] some_value: Vec<u8>
29
30pub fn to_base64<S>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error>
31where S: serde::Serializer {
32    serializer.serialize_str(&base64::encode(bytes))
33}
34
35pub fn from_base64<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
36where D: serde::Deserializer<'de> {
37    let s: String = serde::Deserialize::deserialize(deserializer)?;
38    base64::decode(s).map_err(serde::de::Error::custom)
39}
40
41#[cfg(test)]
42mod tests;