|
@@ -308,7 +308,7 @@ pub fn cmz_privkey_to_pubkey<G: PrimeGroup>(privkey: &CMZPrivkey<G>) -> CMZPubke
|
|
|
/// The CMZCredential trait implemented by all CMZ credential struct types.
|
|
/// The CMZCredential trait implemented by all CMZ credential struct types.
|
|
|
pub trait CMZCredential
|
|
pub trait CMZCredential
|
|
|
where
|
|
where
|
|
|
- Self: Default + Sized,
|
|
|
|
|
|
|
+ for<'a> Self: Default + Sized + serde::Serialize + serde::Deserialize<'a>,
|
|
|
{
|
|
{
|
|
|
/// The type of attributes for this credential
|
|
/// The type of attributes for this credential
|
|
|
type Scalar: PrimeField;
|
|
type Scalar: PrimeField;
|
|
@@ -420,6 +420,21 @@ where
|
|
|
/// example, when you're doing an OR proof, and in some arms of the
|
|
/// example, when you're doing an OR proof, and in some arms of the
|
|
|
/// disjunction, the credential does not have to be valid.
|
|
/// disjunction, the credential does not have to be valid.
|
|
|
fn fake_MAC(&mut self, rng: &mut impl RngCore);
|
|
fn fake_MAC(&mut self, rng: &mut impl RngCore);
|
|
|
|
|
+
|
|
|
|
|
+ /// Serialize this credential, _including_ the private key. The
|
|
|
|
|
+ /// default serializer skips the private key for safety reasons.
|
|
|
|
|
+ fn serialize_with_privkey(&self) -> Vec<u8> {
|
|
|
|
|
+ // Accomplish this by serializing the pair (privkey, self)
|
|
|
|
|
+ bincode::serialize(&(self.get_privkey(), self)).unwrap()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// Deserialize this credential, _including_ the private key. The
|
|
|
|
|
+ /// default serializer skips the private key for safety reasons.
|
|
|
|
|
+ fn deserialize_with_privkey(bytes: &[u8]) -> bincode::Result<Self> {
|
|
|
|
|
+ let (privkey, mut cred) = bincode::deserialize::<(CMZPrivkey<Self::Point>, Self)>(bytes)?;
|
|
|
|
|
+ cred.set_privkey(&privkey);
|
|
|
|
|
+ Ok(cred)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// The CMZ macro for declaring CMZ credentials.
|
|
/// The CMZ macro for declaring CMZ credentials.
|
|
@@ -462,6 +477,8 @@ macro_rules! CMZ {
|
|
|
pub $id: Option<<$G as Group>::Scalar>,
|
|
pub $id: Option<<$G as Group>::Scalar>,
|
|
|
)+
|
|
)+
|
|
|
pub MAC: CMZMac<$G>,
|
|
pub MAC: CMZMac<$G>,
|
|
|
|
|
+ // Don't serialize the private key by default
|
|
|
|
|
+ #[serde(skip)]
|
|
|
privkey: CMZPrivkey<$G>,
|
|
privkey: CMZPrivkey<$G>,
|
|
|
pubkey: CMZPubkey<$G>,
|
|
pubkey: CMZPubkey<$G>,
|
|
|
}
|
|
}
|
|
@@ -476,6 +493,8 @@ macro_rules! CMZ {
|
|
|
pub $id: Option<<G as Group>::Scalar>,
|
|
pub $id: Option<<G as Group>::Scalar>,
|
|
|
)+
|
|
)+
|
|
|
pub MAC: CMZMac<G>,
|
|
pub MAC: CMZMac<G>,
|
|
|
|
|
+ // Don't serialize the private key by default
|
|
|
|
|
+ #[serde(skip)]
|
|
|
privkey: CMZPrivkey<G>,
|
|
privkey: CMZPrivkey<G>,
|
|
|
pubkey: CMZPubkey<G>,
|
|
pubkey: CMZPubkey<G>,
|
|
|
}
|
|
}
|