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