Skip to content

Commit e95ac27

Browse files
committed
key::Key: Remove deprecations
1 parent f17ea49 commit e95ac27

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/core.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl Wormhole {
435435
pub async fn send(&mut self, plaintext: Vec<u8>) -> Result<(), WormholeError> {
436436
let phase_string = Phase::numeric(self.phase);
437437
self.phase += 1;
438-
let data_key = key::derive_phase_key(self.server.side(), &self.key, &phase_string);
438+
let data_key = key::derive_phase_key(self.server.side(), self.key.as_ref(), &phase_string);
439439
let (_nonce, encrypted) = key::encrypt_data(&data_key, &plaintext);
440440
self.server
441441
.send_peer_message(phase_string, encrypted)
@@ -474,7 +474,7 @@ impl Wormhole {
474474

475475
// TODO maybe reorder incoming messages by phase numeral?
476476
let decrypted_message = peer_message
477-
.decrypt(&self.key)
477+
.decrypt(self.key.as_ref())
478478
.ok_or(WormholeError::Crypto)?;
479479

480480
// Send to client

src/core/key.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,9 @@ impl KeyPurpose for GenericKey {}
2929
*
3030
* You don't need to do any crypto, but you might need it to derive subkeys for sub-protocols.
3131
*/
32-
#[derive(Debug, Clone, derive_more::Display, derive_more::Deref)]
32+
#[derive(Debug, Clone, derive_more::Display)]
3333
#[display("{:?}", _0)]
34-
#[deref(forward)]
35-
pub struct Key<P: KeyPurpose>(
36-
#[deref]
37-
#[deprecated(
38-
since = "0.7.0",
39-
note = "Use the AsRef<Key> implementation to get access to the secretbox key"
40-
)]
41-
pub Box<secretbox::Key>,
42-
#[deref(ignore)] std::marker::PhantomData<P>,
43-
);
34+
pub struct Key<P: KeyPurpose>(Box<secretbox::Key>, std::marker::PhantomData<P>);
4435

4536
impl Key<WormholeKey> {
4637
/**
@@ -52,11 +43,7 @@ impl Key<WormholeKey> {
5243
* The new key is derived with the `"{appid}/transit-key"` purpose.
5344
*/
5445
#[cfg(feature = "transit")]
55-
#[deprecated(
56-
since = "0.7.0",
57-
note = "This will be a private method in the future. Open an issue if you require access to protocol intrinsics in the future"
58-
)]
59-
pub fn derive_transit_key(&self, appid: &AppID) -> Key<crate::transit::TransitKey> {
46+
pub(crate) fn derive_transit_key(&self, appid: &AppID) -> Key<crate::transit::TransitKey> {
6047
let transit_purpose = format!("{}/transit-key", appid);
6148
let derived_key = self.derive_subkey_from_purpose(&transit_purpose);
6249
tracing::trace!(
@@ -77,20 +64,32 @@ impl<P: KeyPurpose> Key<P> {
7764

7865
/// Encode a key as a hex string
7966
pub fn to_hex(&self) -> String {
80-
hex::encode(**self)
67+
hex::encode(*self.0)
8168
}
8269

8370
/**
8471
* Derive a new sub-key from this one
8572
*/
8673
pub fn derive_subkey_from_purpose<NewP: KeyPurpose>(&self, purpose: &str) -> Key<NewP> {
8774
Key(
88-
Box::new(derive_key(self, purpose.as_bytes())),
75+
Box::new(derive_key(&self.0, purpose.as_bytes())),
8976
std::marker::PhantomData,
9077
)
9178
}
9279
}
9380

81+
impl<P: KeyPurpose> AsRef<secretbox::Key> for Key<P> {
82+
fn as_ref(&self) -> &secretbox::Key {
83+
&self.0
84+
}
85+
}
86+
87+
impl<P: KeyPurpose> AsRef<[u8]> for Key<P> {
88+
fn as_ref(&self) -> &[u8] {
89+
&self.0.as_slice()
90+
}
91+
}
92+
9493
#[derive(Serialize, Deserialize, Debug)]
9594
struct PhaseMessage {
9695
#[serde(with = "hex::serde")]

src/transit/crypto.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl TransitCryptoInit for NoiseInit {
265265
builder.set_is_initiator(true);
266266
builder.build_handshake_state()
267267
};
268-
handshake.push_psk(&self.key);
268+
handshake.push_psk((*self.key).as_ref());
269269

270270
// → psk, e
271271
socket
@@ -332,7 +332,7 @@ impl TransitCryptoInit for NoiseInit {
332332
builder.set_is_initiator(false);
333333
builder.build_handshake_state()
334334
};
335-
handshake.push_psk(&self.key);
335+
handshake.push_psk((*self.key).as_ref());
336336

337337
// ← psk, e
338338
handshake.read_message(&socket.read_transit_message().await?, &mut [])?;
@@ -408,7 +408,7 @@ impl TransitCryptoEncrypt for SecretboxCryptoEncrypt {
408408
plaintext: &[u8],
409409
) -> Result<(), TransitError> {
410410
let nonce = &mut self.snonce;
411-
let sodium_key = secretbox::Key::from_slice(&self.skey);
411+
let sodium_key = secretbox::Key::from_slice(self.skey.as_ref());
412412

413413
let ciphertext = {
414414
let nonce_le = secretbox::Nonce::from_slice(nonce);
@@ -466,7 +466,8 @@ impl TransitCryptoDecrypt for SecretboxCryptoDecrypt {
466466
crate::util::sodium_increment_be(nonce);
467467
}
468468

469-
let cipher = secretbox::XSalsa20Poly1305::new(secretbox::Key::from_slice(&self.rkey));
469+
let cipher =
470+
secretbox::XSalsa20Poly1305::new(secretbox::Key::from_slice(self.rkey.as_ref()));
470471
cipher
471472
.decrypt(secretbox::Nonce::from_slice(received_nonce), ciphertext)
472473
/* TODO replace with (TransitError::Crypto) after the next xsalsa20poly1305 update */

0 commit comments

Comments
 (0)