Skip to content

Commit 16efb2e

Browse files
committed
Stop using deprecated functions
1 parent 473d976 commit 16efb2e

7 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/cipher/key.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
use std::ops::Deref;
17+
1618
use aes::{
1719
Aes256,
1820
cipher::{Array, IvSizeUser, KeySizeUser},
@@ -98,14 +100,14 @@ impl CipherKeys {
98100
}
99101

100102
pub fn aes_key(&self) -> &Aes256Key {
101-
Aes256Key::from_slice(self.aes_key.as_slice())
103+
self.aes_key.deref().into()
102104
}
103105

104106
pub const fn mac_key(&self) -> &HmacSha256Key {
105107
&self.mac_key
106108
}
107109

108110
pub fn iv(&self) -> &Aes256Iv {
109-
Aes256Iv::from_slice(self.aes_iv.as_slice())
111+
self.aes_iv.deref().into()
110112
}
111113
}

src/ecies/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
//! # Ok::<(), anyhow::Error>(())
7979
//! ```
8080
81+
use std::ops::Deref;
82+
8183
use chacha20poly1305::{ChaCha20Poly1305, Key as Chacha20Key, KeyInit, Nonce, aead::Aead};
8284
use hkdf::Hkdf;
8385
use rand::rng;
@@ -489,11 +491,11 @@ impl EstablishedEcies {
489491
}
490492

491493
fn encryption_key(&self) -> &Chacha20Key {
492-
Chacha20Key::from_slice(self.encryption_key.as_slice())
494+
self.encryption_key.deref().into()
493495
}
494496

495497
fn decryption_key(&self) -> &Chacha20Key {
496-
Chacha20Key::from_slice(self.decryption_key.as_slice())
498+
self.decryption_key.deref().into()
497499
}
498500

499501
/// Encrypt the given plaintext using this [`EstablishedEcies`] session.

src/megolm/ratchet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515

1616
use hmac::{Hmac, KeyInit, Mac as _};
17-
use rand::{RngCore, thread_rng};
17+
use rand::{RngCore, rng};
1818
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1919
use sha2::{Sha256, digest::CtOutput};
2020
use subtle::{Choice, ConstantTimeEq};
@@ -139,7 +139,7 @@ impl Ratchet {
139139
const LAST_RATCHET_INDEX: usize = Self::RATCHET_PART_COUNT - 1;
140140

141141
pub fn new() -> Self {
142-
let mut rng = thread_rng();
142+
let mut rng = rng();
143143

144144
let mut ratchet =
145145
Self { inner: RatchetBytes(Box::new([0u8; Self::RATCHET_LENGTH])), counter: 0 };

src/olm/account/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use chacha20poly1305::{
2121
ChaCha20Poly1305, Nonce,
2222
aead::{Aead, AeadCore, KeyInit},
2323
};
24-
use rand::thread_rng;
24+
use rand::rng;
2525
use serde::{Deserialize, Serialize};
2626
use thiserror::Error;
2727
use x25519_dalek::ReusableSecret;

src/olm/shared_secret.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ impl Shared3DHSecret {
117117

118118
#[cfg(test)]
119119
mod test {
120-
use rand::thread_rng;
120+
use rand::rng;
121121
use x25519_dalek::ReusableSecret;
122122

123123
use super::{RemoteShared3DHSecret, Shared3DHSecret};
124124
use crate::{Curve25519PublicKey as PublicKey, types::Curve25519SecretKey as StaticSecret};
125125

126126
#[test]
127127
fn triple_diffie_hellman() {
128-
let mut rng = thread_rng();
128+
let mut rng = rng();
129129

130130
let alice_identity = StaticSecret::new();
131131
let alice_one_time = ReusableSecret::random_from_rng(&mut rng);

src/sas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
5454
use hkdf::Hkdf;
5555
use hmac::{Hmac, KeyInit, Mac as _, digest::MacError};
56-
use rand::thread_rng;
56+
use rand::rng;
5757
use sha2::Sha256;
5858
use thiserror::Error;
5959
use x25519_dalek::{EphemeralSecret, SharedSecret};

src/types/ed25519.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use ed25519_dalek::Verifier;
2222
use ed25519_dalek::{
2323
PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH, Signature, Signer, SigningKey, VerifyingKey,
2424
};
25-
use rand::thread_rng;
25+
use rand::rng;
2626
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2727
use serde_bytes::{ByteBuf as SerdeByteBuf, Bytes as SerdeBytes};
2828
use sha2::Sha512;
@@ -129,7 +129,7 @@ impl<'d> Deserialize<'d> for ExpandedSecretKey {
129129
impl Ed25519Keypair {
130130
/// Create a new, random, `Ed25519Keypair`.
131131
pub fn new() -> Self {
132-
let mut rng = thread_rng();
132+
let mut rng = rng();
133133
let signing_key = SigningKey::generate(&mut rng);
134134

135135
Self {
@@ -211,7 +211,7 @@ impl Ed25519SecretKey {
211211

212212
/// Create a new random `Ed25519SecretKey`.
213213
pub fn new() -> Self {
214-
let mut rng = thread_rng();
214+
let mut rng = rng();
215215
let signing_key = SigningKey::generate(&mut rng);
216216
let key = Box::new(signing_key);
217217

0 commit comments

Comments
 (0)