Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions dtls/src/cipher_suite/cipher_suite_aes_128_ccm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,16 @@ impl CipherSuite for CipherSuiteAes128Ccm {
}

fn encrypt(&self, pkt_rlh: &RecordLayerHeader, raw: &[u8]) -> Result<Vec<u8>> {
if let Some(ccm) = &self.ccm {
ccm.encrypt(pkt_rlh, raw)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))
}
let ccm = self.ccm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))?;
ccm.encrypt(pkt_rlh, raw)
}

fn decrypt(&self, input: &[u8]) -> Result<Vec<u8>> {
if let Some(ccm) = &self.ccm {
ccm.decrypt(input)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))
}
let ccm = self.ccm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))?;
ccm.decrypt(input)
}
}
22 changes: 8 additions & 14 deletions dtls/src/cipher_suite/cipher_suite_aes_128_gcm_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,16 @@ impl CipherSuite for CipherSuiteAes128GcmSha256 {
}

fn encrypt(&self, pkt_rlh: &RecordLayerHeader, raw: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.gcm {
cg.encrypt(pkt_rlh, raw)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))
}
let cg = self.gcm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))?;
cg.encrypt(pkt_rlh, raw)
}

fn decrypt(&self, input: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.gcm {
cg.decrypt(input)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))
}
let cg = self.gcm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))?;
cg.decrypt(input)
}
}
22 changes: 8 additions & 14 deletions dtls/src/cipher_suite/cipher_suite_aes_256_cbc_sha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,16 @@ impl CipherSuite for CipherSuiteAes256CbcSha {
}

fn encrypt(&self, pkt_rlh: &RecordLayerHeader, raw: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.cbc {
cg.encrypt(pkt_rlh, raw)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))
}
let cg = self.cbc.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))?;
cg.encrypt(pkt_rlh, raw)
}

fn decrypt(&self, input: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.cbc {
cg.decrypt(input)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))
}
let cg = self.cbc.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))?;
cg.decrypt(input)
}
}
22 changes: 8 additions & 14 deletions dtls/src/cipher_suite/cipher_suite_chacha20_poly1305_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,16 @@ impl CipherSuite for CipherSuiteChaCha20Poly1305Sha256 {
}

fn encrypt(&self, pkt_rlh: &RecordLayerHeader, raw: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.cipher {
cg.encrypt(pkt_rlh, raw)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))
}
let cg = self.cipher.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))?;
cg.encrypt(pkt_rlh, raw)
}

fn decrypt(&self, input: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.cipher {
cg.decrypt(input)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))
}
let cg = self.cipher.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))?;
cg.decrypt(input)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,16 @@ impl CipherSuite for CipherSuiteTlsPskWithAes128GcmSha256 {
}

fn encrypt(&self, pkt_rlh: &RecordLayerHeader, raw: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.gcm {
cg.encrypt(pkt_rlh, raw)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))
}
let cg = self.gcm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to encrypt".to_owned(),
))?;
cg.encrypt(pkt_rlh, raw)
}

fn decrypt(&self, input: &[u8]) -> Result<Vec<u8>> {
if let Some(cg) = &self.gcm {
cg.decrypt(input)
} else {
Err(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))
}
let cg = self.gcm.as_ref().ok_or(Error::Other(
"CipherSuite has not been initialized, unable to decrypt".to_owned(),
))?;
cg.decrypt(input)
}
}
Loading