Skip to content

Commit

Permalink
simplify UnlockKey serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jul 10, 2024
1 parent d16fc5b commit 430df13
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,7 @@ impl Serialize for UnlockKey {
if serializer.is_human_readable() {
String::serialize(&self.to_string(), serializer)
} else {
#[derive(Serialize)]
struct NotHumanReadable<'a> {
algorithm: Algorithm,
public_key: &'a [u8], // public_key needs to be length prefixed
}
NotHumanReadable::serialize(
&NotHumanReadable {
algorithm: self.algorithm,
public_key: self.public_key.as_ref(),
},
serializer,
)
<(Algorithm, &[u8])>::serialize(&(self.algorithm, self.public_key.as_ref()), serializer)
}
}
}
Expand All @@ -49,15 +38,10 @@ impl<'de> Deserialize<'de> for UnlockKey {
let s = String::deserialize(deserializer)?;
UnlockKey::parse_string(&s).map_err(|e| serde::de::Error::custom(format!("{:?}", e)))
} else {
#[derive(Deserialize)]
struct NotHumanReadable {
algorithm: Algorithm,
public_key: PublicKey,
}
let result = NotHumanReadable::deserialize(deserializer)?;
let (algorithm, public_key) = <(Algorithm, [u8; 32])>::deserialize(deserializer)?;
Ok(Self {
algorithm: result.algorithm,
public_key: result.public_key,
algorithm,
public_key: PublicKey::new(public_key),
})
}
}
Expand Down

0 comments on commit 430df13

Please sign in to comment.