More FFI fixes, a few missing functions and changes of types
This commit is contained in:
parent
d9d3bee790
commit
ed09f6044e
@ -192,6 +192,10 @@ impl Fingerprint {
|
||||
scannable: ScannableFingerprint::new(version, &local_fingerprint, &remote_fingerprint),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn display_string(&self) -> Result<String> {
|
||||
Ok(format!("{}", self.display))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -38,7 +38,9 @@ pub use {
|
||||
are_we_alice, initialize_alice_session, initialize_bob_session,
|
||||
AliceSignalProtocolParameters, BobSignalProtocolParameters, ChainKey, MessageKeys, RootKey,
|
||||
},
|
||||
sender_keys::{SenderKeyName, SenderKeyRecord},
|
||||
sender_keys::{
|
||||
SenderChainKey, SenderKeyName, SenderKeyRecord, SenderKeyState, SenderMessageKey,
|
||||
},
|
||||
session::*,
|
||||
session_cipher::SessionCipher,
|
||||
state::{PreKeyBundle, PreKeyRecord, SessionRecord, SessionState, SignedPreKeyRecord},
|
||||
|
||||
@ -38,12 +38,12 @@ pub struct SenderMessageKey {
|
||||
}
|
||||
|
||||
impl SenderMessageKey {
|
||||
pub fn new(iteration: u32, seed: &[u8]) -> Result<Self> {
|
||||
pub fn new(iteration: u32, seed: Vec<u8>) -> Result<Self> {
|
||||
let hkdf = HKDF::new(3)?;
|
||||
let derived = hkdf.derive_secrets(seed, b"WhisperGroup", 48)?;
|
||||
let derived = hkdf.derive_secrets(&seed, b"WhisperGroup", 48)?;
|
||||
Ok(Self {
|
||||
iteration,
|
||||
seed: seed.to_vec(),
|
||||
seed: seed,
|
||||
iv: derived[0..16].to_vec(),
|
||||
cipher_key: derived[16..48].to_vec(),
|
||||
})
|
||||
@ -52,7 +52,7 @@ impl SenderMessageKey {
|
||||
pub fn from_protobuf(
|
||||
smk: storage_proto::sender_key_state_structure::SenderMessageKey,
|
||||
) -> Result<Self> {
|
||||
Self::new(smk.iteration, &smk.seed)
|
||||
Self::new(smk.iteration, smk.seed)
|
||||
}
|
||||
|
||||
pub fn iteration(&self) -> Result<u32> {
|
||||
@ -118,7 +118,7 @@ impl SenderChainKey {
|
||||
pub fn sender_message_key(&self) -> Result<SenderMessageKey> {
|
||||
Ok(SenderMessageKey::new(
|
||||
self.iteration,
|
||||
&self.get_derivative(Self::MESSAGE_KEY_SEED)?,
|
||||
self.get_derivative(Self::MESSAGE_KEY_SEED)?,
|
||||
)?)
|
||||
}
|
||||
|
||||
@ -168,10 +168,21 @@ impl SenderKeyState {
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
pub fn deserialize(buf: &[u8]) -> Result<Self> {
|
||||
let state = storage_proto::SenderKeyStateStructure::decode(buf)?;
|
||||
Ok(Self { state })
|
||||
}
|
||||
|
||||
pub fn from_protobuf(state: storage_proto::SenderKeyStateStructure) -> Self {
|
||||
Self { state }
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Result<Vec<u8>> {
|
||||
let mut buf = vec![];
|
||||
self.state.encode(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
pub fn sender_key_id(&self) -> Result<u32> {
|
||||
Ok(self.state.sender_key_id)
|
||||
}
|
||||
@ -206,7 +217,7 @@ impl SenderKeyState {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_sender_key_message(&self, iteration: u32) -> Result<bool> {
|
||||
pub fn has_sender_message_key(&self, iteration: u32) -> Result<bool> {
|
||||
for sender_message_key in &self.state.sender_message_keys {
|
||||
if sender_message_key.iteration == iteration {
|
||||
return Ok(true);
|
||||
@ -339,4 +350,10 @@ impl SenderKeyRecord {
|
||||
sender_key_states: states,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Result<Vec<u8>> {
|
||||
let mut buf = vec![];
|
||||
self.as_protobuf()?.encode(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,9 +144,9 @@ pub fn process_prekey_bundle<R: Rng + CryptoRng>(
|
||||
our_identity_key_pair,
|
||||
our_base_key_pair,
|
||||
*their_identity_key,
|
||||
*their_signed_prekey,
|
||||
*their_one_time_prekey,
|
||||
*their_signed_prekey,
|
||||
their_signed_prekey,
|
||||
their_one_time_prekey,
|
||||
their_signed_prekey,
|
||||
);
|
||||
|
||||
let mut session = ratchet::initialize_alice_session(¶meters, csprng)?;
|
||||
|
||||
@ -55,16 +55,16 @@ impl PreKeyBundle {
|
||||
Ok(self.pre_key_id)
|
||||
}
|
||||
|
||||
pub fn pre_key_public(&self) -> Result<&Option<curve::PublicKey>> {
|
||||
Ok(&self.pre_key_public)
|
||||
pub fn pre_key_public(&self) -> Result<Option<curve::PublicKey>> {
|
||||
Ok(self.pre_key_public)
|
||||
}
|
||||
|
||||
pub fn signed_pre_key_id(&self) -> Result<SignedPreKeyId> {
|
||||
Ok(self.signed_pre_key_id)
|
||||
}
|
||||
|
||||
pub fn signed_pre_key_public(&self) -> Result<&curve::PublicKey> {
|
||||
Ok(&self.signed_pre_key_public)
|
||||
pub fn signed_pre_key_public(&self) -> Result<curve::PublicKey> {
|
||||
Ok(self.signed_pre_key_public)
|
||||
}
|
||||
|
||||
pub fn signed_pre_key_signature(&self) -> Result<&[u8]> {
|
||||
|
||||
@ -54,14 +54,14 @@ pub trait SignedPreKeyStore {
|
||||
pub trait SessionStore {
|
||||
fn load_session(&self, address: &ProtocolAddress) -> Result<Option<SessionRecord>>;
|
||||
|
||||
fn get_sub_device_sessions(&self, name: &str) -> Result<Vec<u32>>;
|
||||
|
||||
fn store_session(&mut self, address: &ProtocolAddress, record: &SessionRecord) -> Result<()>;
|
||||
|
||||
fn contains_session(&self, address: &ProtocolAddress) -> Result<bool>;
|
||||
|
||||
fn delete_session(&mut self, address: &ProtocolAddress) -> Result<()>;
|
||||
|
||||
fn get_sub_device_sessions(&self, name: &str) -> Result<Vec<u32>>;
|
||||
|
||||
fn delete_all_sessions(&mut self, name: &str) -> Result<()>;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user