|
@@ -5,8 +5,9 @@ use crate::{
|
|
|
token::{TokenManager, TokenPayload},
|
|
|
AccountId, Amount, FilterableValue, MaxLengthString, PaymentFrom, RevId, Status, TxId,
|
|
|
};
|
|
|
+use base64::{engine::general_purpose, Engine as _};
|
|
|
use chrono::{DateTime, Duration, TimeZone, Utc};
|
|
|
-use serde::{Deserialize, Serialize};
|
|
|
+use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
mod base_tx;
|
|
@@ -19,6 +20,24 @@ pub use self::{base_tx::BaseTx, error::Error, revision::Revision, typ::Type};
|
|
|
/// Tag definition
|
|
|
pub type Tag = MaxLengthString<64>;
|
|
|
|
|
|
+pub(crate) fn serialize_base64<S>(bytes: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
+where
|
|
|
+ S: Serializer,
|
|
|
+{
|
|
|
+ let encoded = general_purpose::STANDARD_NO_PAD.encode(bytes);
|
|
|
+ serializer.serialize_str(&encoded)
|
|
|
+}
|
|
|
+
|
|
|
+pub(crate) fn deserialize_base64<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
|
|
|
+where
|
|
|
+ D: Deserializer<'de>,
|
|
|
+{
|
|
|
+ let s = String::deserialize(deserializer)?;
|
|
|
+ general_purpose::STANDARD_NO_PAD
|
|
|
+ .decode(&s)
|
|
|
+ .map_err(serde::de::Error::custom)
|
|
|
+}
|
|
|
+
|
|
|
pub(crate) fn to_ts_microseconds<W: std::io::Write>(
|
|
|
dt: &DateTime<Utc>,
|
|
|
writer: &mut W,
|