Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
beltram committed Nov 27, 2023
1 parent 03665b3 commit e261edb
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 23 deletions.
4 changes: 2 additions & 2 deletions crypto-ffi/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ impl CoreCrypto {
conversation_id: Vec<u8>,
keypackage: Vec<u8>,
) -> CoreCryptoResult<ProposalBundle> {
let kp = KeyPackageIn::tls_deserialize_bytes(keypackage)
let kp = KeyPackageIn::tls_deserialize_exact(keypackage)
.map_err(MlsError::from)
.map_err(CryptoError::from)?;
self.central
Expand Down Expand Up @@ -1145,7 +1145,7 @@ impl CoreCrypto {
custom_configuration: CustomConfiguration,
credential_type: MlsCredentialType,
) -> CoreCryptoResult<ConversationInitBundle> {
let group_info = VerifiableGroupInfo::tls_deserialize_bytes(group_info)
let group_info = VerifiableGroupInfo::tls_deserialize_exact(group_info)
.map_err(MlsError::from)
.map_err(CryptoError::from)?;
self.central
Expand Down
4 changes: 2 additions & 2 deletions crypto-ffi/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ impl CoreCrypto {
let this = self.inner.clone();
future_to_promise(
async move {
let kp = KeyPackageIn::tls_deserialize_bytes(keypackage)
let kp = KeyPackageIn::tls_deserialize_exact(keypackage)
.map_err(MlsError::from)
.map_err(CryptoError::from)
.map_err(CoreCryptoError::from)?;
Expand Down Expand Up @@ -1902,7 +1902,7 @@ impl CoreCrypto {
let this = self.inner.clone();
future_to_promise(
async move {
let group_info = VerifiableGroupInfo::tls_deserialize_bytes(&group_info)
let group_info = VerifiableGroupInfo::tls_deserialize_exact(&group_info)
.map_err(MlsError::from)
.map_err(CryptoError::from)
.map_err(CoreCryptoError::from)?;
Expand Down
2 changes: 1 addition & 1 deletion crypto/benches/utils/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub async fn add_clients(
.unwrap();

let group_info = commit_bundle.group_info.payload.bytes();
let group_info = openmls::prelude::MlsMessageIn::tls_deserialize_bytes(&group_info[..]).unwrap();
let group_info = openmls::prelude::MlsMessageIn::tls_deserialize_exact(&group_info[..]).unwrap();
let MlsMessageInBody::GroupInfo(group_info) = group_info.extract() else {
panic!("error")
};
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/e2e_identity/rotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ pub mod tests {
.into_iter()
.map(|c| {
let credential =
openmls::prelude::Credential::tls_deserialize_bytes(c.credential.as_slice()).unwrap();
openmls::prelude::Credential::tls_deserialize_exact(c.credential.as_slice()).unwrap();
(credential, c.created_at)
})
.collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/mls/client/key_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Client {
if all_to_delete {
// then delete this Credential
MlsCredential::delete_by_credential(&mut conn, credential.clone()).await?;
let credential = Credential::tls_deserialize_bytes(credential).map_err(MlsError::from)?;
let credential = Credential::tls_deserialize_exact(credential).map_err(MlsError::from)?;
self.identities.remove(&credential)?;
}
}
Expand Down
11 changes: 5 additions & 6 deletions crypto/src/mls/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ impl Client {
.into_iter()
.filter(|c| &c.id[..] == id.as_slice())
.try_fold(vec![], |mut acc, c| {
use tls_codec::Deserialize as _;
let credential = Credential::tls_deserialize_bytes(c.credential.as_slice()).map_err(MlsError::from)?;
let credential = Credential::tls_deserialize_exact(c.credential.as_slice()).map_err(MlsError::from)?;
acc.push((credential, c.created_at));
CryptoResult::Ok(acc)
})?;
Expand Down Expand Up @@ -216,7 +215,7 @@ impl Client {
.await?;

let signature_key =
SignatureKeyPair::tls_deserialize_bytes(&new_keypair.keypair).map_err(MlsError::from)?;
SignatureKeyPair::tls_deserialize_exact(&new_keypair.keypair).map_err(MlsError::from)?;
let cb = CredentialBundle {
credential: Credential::new_basic(new_credential.credential.clone()),
signature_key,
Expand Down Expand Up @@ -292,14 +291,14 @@ impl Client {
let kp = store_skps.iter().find(|skp| skp.signature_scheme == (sc as u16));

let signature_key = if let Some(kp) = kp {
SignatureKeyPair::tls_deserialize_bytes(&kp.keypair).map_err(MlsError::from)?
SignatureKeyPair::tls_deserialize_exact(&kp.keypair).map_err(MlsError::from)?
} else {
let (sk, pk) = backend.crypto().signature_key_gen(sc).map_err(MlsError::from)?;
let keypair = SignatureKeyPair::from_raw(sc, sk, pk.clone());
let raw_keypair = keypair.tls_serialize_detached().map_err(MlsError::from)?;
let store_keypair = MlsSignatureKeyPair::new(sc, pk, raw_keypair, id.as_slice().into());
backend.key_store().save(store_keypair.clone()).await?;
SignatureKeyPair::tls_deserialize_bytes(&store_keypair.keypair).map_err(MlsError::from)?
SignatureKeyPair::tls_deserialize_exact(&store_keypair.keypair).map_err(MlsError::from)?
};

for (credential, created_at) in &credentials {
Expand Down Expand Up @@ -339,7 +338,7 @@ impl Client {
.await?;
let mut credentials = Vec::with_capacity(store_credentials.len());
for store_credential in store_credentials.into_iter() {
let credential = Credential::tls_deserialize_bytes(&store_credential.credential).map_err(MlsError::from)?;
let credential = Credential::tls_deserialize_exact(&store_credential.credential).map_err(MlsError::from)?;
if !matches!(credential.credential_type(), CredentialType::Basic) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/mls/conversation/buffer_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl MlsConversation {
.into_iter()
.filter(|pm| pm.id == group_id)
.try_fold(vec![], |mut acc, m| {
let msg = MlsMessageIn::tls_deserialize_bytes(m.message.as_slice()).map_err(MlsError::from)?;
let msg = MlsMessageIn::tls_deserialize_exact(m.message.as_slice()).map_err(MlsError::from)?;
let ct = match msg.body_as_ref() {
MlsMessageInBody::PublicMessage(m) => Ok(m.content_type()),
MlsMessageInBody::PrivateMessage(m) => Ok(m.content_type()),
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/mls/conversation/decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl MlsCentral {
id: &ConversationId,
message: impl AsRef<[u8]>,
) -> CryptoResult<MlsConversationDecryptMessage> {
let msg = MlsMessageIn::tls_deserialize_bytes(message.as_ref()).map_err(MlsError::from)?;
let msg = MlsMessageIn::tls_deserialize_exact(message.as_ref()).map_err(MlsError::from)?;
let Ok(conversation) = self.get_conversation(id).await else {
return self.handle_when_group_is_pending(id, message).await;
};
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/mls/conversation/group_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl MlsGroupInfoBundle {
use tls_codec::Deserialize as _;
match &mut self.payload {
GroupInfoPayload::Plaintext(gi) => {
openmls::prelude::MlsMessageIn::tls_deserialize_bytes(gi.as_slice()).unwrap()
openmls::prelude::MlsMessageIn::tls_deserialize_exact(gi.as_slice()).unwrap()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/mls/member.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ConversationMember {
/// # Errors
/// Deserialization errors
pub fn new_raw(client_id: ClientId, kp_ser: Vec<u8>, backend: &MlsCryptoProvider) -> CryptoResult<Self> {
let kp = KeyPackageIn::tls_deserialize_bytes(kp_ser).map_err(MlsError::from)?;
let kp = KeyPackageIn::tls_deserialize_exact(kp_ser).map_err(MlsError::from)?;
let kp = kp
.standalone_validate(backend.crypto(), openmls::versions::ProtocolVersion::Mls10)
.map_err(MlsError::from)?;
Expand Down Expand Up @@ -103,7 +103,7 @@ impl ConversationMember {
/// # Errors
/// Deserialization errors
pub fn add_keypackage(&mut self, kp: Vec<u8>, backend: &MlsCryptoProvider) -> CryptoResult<()> {
let kp = KeyPackageIn::tls_deserialize_bytes(kp).map_err(MlsError::from)?;
let kp = KeyPackageIn::tls_deserialize_exact(kp).map_err(MlsError::from)?;
let kp = kp
.standalone_validate(backend.crypto(), openmls::versions::ProtocolVersion::Mls10)
.map_err(MlsError::from)?;
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/test_utils/central.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ impl MlsCentral {

// the keystore
let credential = self.find_credential_from_keystore(&cb).await.unwrap();
let credential = Credential::tls_deserialize_bytes(credential.credential.as_slice()).unwrap();
let credential = Credential::tls_deserialize_exact(credential.credential.as_slice()).unwrap();
assert_eq!(credential.identity(), &cid.0);
let keystore_identity = credential.extract_identity().unwrap().unwrap();
assert_eq!(keystore_identity.display_name, new_display_name);
Expand Down
2 changes: 1 addition & 1 deletion interop/src/clients/corecrypto/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ window.cc.clientKeypackages(ciphersuite, window.credentialType, 1).then(([kp]) =
.await
.and_then(|value| Ok(serde_json::from_value(value)?))?;

let kp: KeyPackage = KeyPackageIn::tls_deserialize_bytes(&kp_raw)?.into();
let kp: KeyPackage = KeyPackageIn::tls_deserialize_exact(&kp_raw)?.into();

log::info!(
"KP Init Key [took {}ms]: Client {} [{}] - {}",
Expand Down
4 changes: 2 additions & 2 deletions keystore-dump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async fn main() -> Result<()> {
.await?
.into_iter()
{
let mls_credential = openmls::prelude::Credential::tls_deserialize_bytes(&cred.credential)?;
let mls_credential = openmls::prelude::Credential::tls_deserialize_exact(&cred.credential)?;
let date = chrono::Utc
.timestamp_opt(cred.created_at as i64, 0)
.single()
Expand All @@ -65,7 +65,7 @@ async fn main() -> Result<()> {
.await?
.into_iter()
{
let mls_keypair = openmls_basic_credential::SignatureKeyPair::tls_deserialize_bytes(&kp.keypair)?;
let mls_keypair = openmls_basic_credential::SignatureKeyPair::tls_deserialize_exact(&kp.keypair)?;
signature_keypairs.push(serde_json::json!({
"signature_scheme": kp.signature_scheme,
"mls_keypair": mls_keypair,
Expand Down
2 changes: 1 addition & 1 deletion keystore/tests/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub mod tests {

assert_eq!(keypair2.credential_id, credential2.id);

let keypair2 = SignatureKeyPair::tls_deserialize_bytes(&keypair2.keypair).unwrap();
let keypair2 = SignatureKeyPair::tls_deserialize_exact(&keypair2.keypair).unwrap();

let (b1_kp, b1_sk) = (keypair.to_public_vec(), keypair.private().to_vec());
let (b2_kp, b2_sk) = (keypair2.to_public_vec(), keypair.private().to_vec());
Expand Down

0 comments on commit e261edb

Please sign in to comment.