mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-03 04:55:32 +00:00
refactor(types): WithSig
-> Signed
This commit is contained in:
parent
73eb441a26
commit
93d1589730
7 changed files with 39 additions and 39 deletions
|
@ -60,7 +60,7 @@ impl fmt::Display for UserKey {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct WithSig<T> {
|
||||
pub struct Signed<T> {
|
||||
#[serde(with = "hex::serde")]
|
||||
pub sig: [u8; SIGNATURE_LENGTH],
|
||||
pub signee: Signee<T>,
|
||||
|
@ -82,7 +82,7 @@ pub fn get_timestamp() -> u64 {
|
|||
.as_secs()
|
||||
}
|
||||
|
||||
impl<T: Serialize> WithSig<T> {
|
||||
impl<T: Serialize> Signed<T> {
|
||||
/// Sign the payload with the given `key`.
|
||||
pub fn sign(
|
||||
key: &SigningKey,
|
||||
|
@ -308,7 +308,7 @@ impl RichText {
|
|||
}
|
||||
}
|
||||
|
||||
pub type SignedChatMsg = WithSig<ChatPayload>;
|
||||
pub type SignedChatMsg = Signed<ChatPayload>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct RoomMetadata {
|
||||
|
@ -551,7 +551,7 @@ mod tests {
|
|||
let mut fake_rng = rand::rngs::mock::StepRng::new(0x42, 1);
|
||||
let signing_key = SigningKey::from_bytes(&[0x42; 32]);
|
||||
let timestamp = 0xDEAD_BEEF;
|
||||
let msg = WithSig::sign(
|
||||
let msg = Signed::sign(
|
||||
&signing_key,
|
||||
timestamp,
|
||||
&mut fake_rng,
|
||||
|
@ -568,7 +568,7 @@ mod tests {
|
|||
]];
|
||||
expect.assert_eq(&json);
|
||||
|
||||
let roundtrip_msg = serde_json::from_str::<WithSig<ChatPayload>>(&json).unwrap();
|
||||
let roundtrip_msg = serde_json::from_str::<Signed<ChatPayload>>(&json).unwrap();
|
||||
assert_eq!(roundtrip_msg, msg);
|
||||
roundtrip_msg.verify().unwrap();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue