update applying pending balance for aes ciphertext

This commit is contained in:
Sam Kim 2021-10-11 18:43:10 -04:00 committed by Michael Vines
parent 2d225de48c
commit 57103c515b
3 changed files with 41 additions and 2 deletions

View File

@ -47,7 +47,7 @@ impl AESKey {
}
#[derive(Debug)]
pub struct AESCiphertext([u8; 16]);
pub struct AESCiphertext(pub [u8; 16]);
impl AESCiphertext {
pub fn decrypt(&self, sk: &AESKey) -> u64 {
AES::decrypt(sk, self)

View File

@ -22,7 +22,7 @@ mod target_arch {
range_proof::RangeProof,
},
curve25519_dalek::{ristretto::CompressedRistretto, scalar::Scalar},
std::convert::TryFrom,
std::convert::{TryFrom, TryInto},
};
impl From<Scalar> for pod::Scalar {
@ -136,6 +136,30 @@ mod target_arch {
}
}
impl From<Option<AESCiphertext>> for pod::OptionAESCiphertext {
fn from(ct: Option<AESCiphertext>) -> Self {
let mut buf = [0_u8; 17];
match ct {
Some(ct) => {
buf[0] = 1_u8;
buf[1..].copy_from_slice(&ct.0);
Self(buf)
},
None => Self(buf),
}
}
}
impl From<pod::OptionAESCiphertext> for Option<AESCiphertext> {
fn from(ct: pod::OptionAESCiphertext) -> Self {
if ct.0[0] == 0 {
None
} else {
Some(AESCiphertext(ct.0[1..17].try_into().unwrap()))
}
}
}
impl TryFrom<RangeProof> for pod::RangeProof64 {
type Error = ProofError;

View File

@ -80,3 +80,18 @@ impl fmt::Debug for AESCiphertext {
write!(f, "{:?}", self.0)
}
}
/// Temporary serialization of Option<AESCiphertext>
#[derive(Clone, Copy, Pod, Zeroable, PartialEq)]
#[repr(transparent)]
pub struct OptionAESCiphertext(pub [u8; 17]);
impl fmt::Debug for OptionAESCiphertext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.0[0] == 1_u8 {
write!(f, "Some({:?})", &self.0[1..17])
} else {
write!(f, "None")
}
}
}