Skip to content

Commit

Permalink
chore: fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
beltram committed Jan 5, 2024
1 parent 28a9bbb commit 2eda117
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
9 changes: 4 additions & 5 deletions openmls/src/credentials/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ impl tls_codec::Size for Credential {
fn tls_serialized_len(&self) -> usize {
self.credential_type.tls_serialized_len()
+ match &self.credential {
MlsCredentialType::Basic(c) => c.tls_serialized_len(),
MlsCredentialType::X509(c) => c.tls_serialized_len(),
}
MlsCredentialType::Basic(c) => c.tls_serialized_len(),
MlsCredentialType::X509(c) => c.tls_serialized_len(),
}
}
}

Expand All @@ -32,8 +32,7 @@ impl tls_codec::Serialize for Credential {
impl tls_codec::Deserialize for Credential {
fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, tls_codec::Error> {
let val = u16::tls_deserialize(bytes)?;
let credential_type = CredentialType::try_from(val)
.map_err(|e| tls_codec::Error::DecodingError(e.to_string()))?;
let credential_type = CredentialType::from(val);
match credential_type {
CredentialType::Basic => Ok(Credential::from(MlsCredentialType::Basic(
BasicCredential::tls_deserialize(bytes)?,
Expand Down
26 changes: 12 additions & 14 deletions openmls/src/credentials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
//! There are multiple [`CredentialType`]s, although OpenMLS currently only
//! supports the [`BasicCredential`].
use std::{
convert::TryFrom,
io::{Read, Write},
};
use std::io::{Read, Write};

use serde::{Deserialize, Serialize};
use tls_codec::{TlsDeserialize, TlsSerialize, TlsSize, VLBytes};
Expand All @@ -34,6 +31,7 @@ use tls_codec::{TlsDeserialize, TlsSerialize, TlsSize, VLBytes};
mod codec;
#[cfg(test)]
mod tests;

use errors::*;
use openmls_x509_credential::X509Ext;
use x509_cert::{der::Decode, PkiPath};
Expand Down Expand Up @@ -93,8 +91,8 @@ impl tls_codec::Size for CredentialType {

impl tls_codec::Deserialize for CredentialType {
fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, tls_codec::Error>
where
Self: Sized,
where
Self: Sized,
{
let mut extension_type = [0u8; 2];
bytes.read_exact(&mut extension_type)?;
Expand Down Expand Up @@ -162,8 +160,8 @@ impl tls_codec::Serialize for Certificate {

impl tls_codec::Deserialize for Certificate {
fn tls_deserialize<R: Read>(bytes: &mut R) -> Result<Self, tls_codec::Error>
where
Self: Sized,
where
Self: Sized,
{
let certificates = Vec::<Vec<u8>>::tls_deserialize(bytes)?;
// we should not do this in a deserializer but otherwise we have to deal with a `identity: Option<Vec<u8>>` everywhere
Expand All @@ -184,7 +182,7 @@ impl Certificate {

fn try_new(certificates: Vec<Vec<u8>>) -> Result<Self, CredentialError> {
let leaf = certificates
.get(0)
.first()
.ok_or(CredentialError::InvalidCertificateChain)?;
let leaf = x509_cert::Certificate::from_der(leaf)?;
let identity = leaf
Expand All @@ -201,7 +199,7 @@ impl Certificate {
///
/// This enum contains variants containing the different available credentials.
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
Debug, PartialEq, Eq, Clone, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
)]
#[repr(u8)]
pub enum MlsCredentialType {
Expand Down Expand Up @@ -298,7 +296,7 @@ impl From<MlsCredentialType> for Credential {
/// OpenMLS provides an implementation of signature keys for convenience in the
/// `openmls_basic_credential` crate.
#[derive(
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, TlsSerialize, TlsDeserialize, TlsSize,
)]
pub struct BasicCredential {
identity: VLBytes,
Expand Down Expand Up @@ -348,7 +346,7 @@ pub mod test_utils {
signature_scheme,
Some(cert_data),
)
.await
.await
}

/// Convenience function that generates a new credential and a key pair for
Expand All @@ -368,7 +366,7 @@ pub mod test_utils {
signature_scheme,
None,
)
.await
.await
}

async fn build_credential(
Expand All @@ -387,7 +385,7 @@ pub mod test_utils {
signature_scheme,
&mut *backend.rand().borrow_rand().unwrap(),
)
.unwrap();
.unwrap();
signature_keys.store(backend.key_store()).await.unwrap();

(
Expand Down
1 change: 0 additions & 1 deletion openmls/src/group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub use core_group::proposals::*;
pub use core_group::staged_commit::StagedCommit;
pub use mls_group::config::*;
pub use mls_group::membership::*;
pub use mls_group::processing::*;
pub use mls_group::*;
pub use public_group::*;

Expand Down
7 changes: 2 additions & 5 deletions openmls/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// MlsGroup
pub use crate::group::{config::CryptoConfig, core_group::Member, errors::*, ser::*, *};

pub use crate::group::public_group::{errors::*, process::*, *};
pub use crate::group::public_group::errors::*;

// Ciphersuite
pub use crate::ciphersuite::{hash_ref::KeyPackageRef, signable::*, signature::*, *};
Expand All @@ -25,11 +25,8 @@ pub use crate::extensions::{errors::*, *};

// Framing
pub use crate::framing::{
message_in::*,
message_out::{MlsMessageOutBody, *},
message_out::MlsMessageOutBody,
mls_content_in::FramedContentBodyIn,
sender::*,
validation::*,
*,
};

Expand Down
2 changes: 1 addition & 1 deletion x509_credential/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CertificateKeyPair {
},
)?;

let leaf = pki_path.get(0).ok_or(CryptoError::CryptoLibraryError)?;
let leaf = pki_path.first().ok_or(CryptoError::CryptoLibraryError)?;

let signature_scheme = leaf.signature_scheme()?;
let pk = leaf.public_key()?;
Expand Down

0 comments on commit 2eda117

Please sign in to comment.