Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
skip decrypting key in keyload if present
Browse files Browse the repository at this point in the history
  • Loading branch information
DyrellC committed May 30, 2022
1 parent a6f9914 commit f17931e
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions streams/src/message/keyload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ where
let mut subscriber_id = Permissioned::<Identifier>::default();
fork.mask(&mut subscriber_id)?;

if subscriber_id.identifier() == &keyload.user_id.to_identifier() {
if key.is_some() {
fork.drop(KEY_SIZE + x25519::PUBLIC_KEY_LENGTH)?;
} else if subscriber_id.identifier() == &keyload.user_id.to_identifier() {
fork.decrypt(
keyload.user_id,
&keyload.user_id._ke_sk().to_bytes(),
Expand All @@ -250,16 +252,20 @@ where
let mut psk_id = PskId::default();
fork.mask(&mut psk_id)?;

let mut masked_key = [0u8; KEY_SIZE];
if let Some(psk) = keyload.psk_store.get(&psk_id) {
fork.absorb(External::new(&NBytes::new(psk)))?
.commit()?
.mask(NBytes::new(&mut masked_key))?;
key = Some(masked_key);

keyload.psks.push(psk_id);
} else {
if key.is_some() {
fork.drop(KEY_SIZE)?;
} else {
let mut masked_key = [0u8; KEY_SIZE];
if let Some(psk) = keyload.psk_store.get(&psk_id) {
fork.absorb(External::new(&NBytes::new(psk)))?
.commit()?
.mask(NBytes::new(&mut masked_key))?;
key = Some(masked_key);

keyload.psks.push(psk_id);
} else {
fork.drop(KEY_SIZE)?;
}
}
}

Expand Down

0 comments on commit f17931e

Please sign in to comment.