Skip to content

Commit bd2c536

Browse files
committed
feat(bindings/crypto-nodejs): Use latest napi-rs version to avoid cloning Uint8Array.
The new `napi-rs` release includes a patch that avoids cloning and copying data inside a `Uint8Array` (napi-rs/napi-rs#1224), it now returns a “Node.js reference” of it. This new `napi-rs` release also includes one of our patch, napi-rs/napi-rs#1200, which means we no longer need to depend on our fork.
1 parent 0a32c8c commit bd2c536

File tree

2 files changed

+5
-13
lines changed

2 files changed

+5
-13
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ matrix-sdk-common = { version = "0.5.0", path = "../../crates/matrix-sdk-common"
3030
matrix-sdk-sled = { version = "0.1.0", path = "../../crates/matrix-sdk-sled", default-features = false, features = ["crypto-store"] }
3131
ruma = { git = "https://github.com/ruma/ruma", rev = "96155915f", features = ["client-api-c", "rand", "unstable-msc2676", "unstable-msc2677"] }
3232
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36" }
33-
napi = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26", default-features = false, features = ["napi6", "tokio_rt"] }
34-
napi-derive = { git = "https://github.com/Hywan/napi-rs", branch = "feat-either-n-up-to-26" }
33+
napi = { version = "2.6.1", default-features = false, features = ["napi6", "tokio_rt"] }
34+
napi-derive = "2.6.0"
3535
serde_json = "1.0.79"
3636
http = "0.2.6"
3737
zeroize = "1.3.0"

src/attachment.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ impl Attachment {
6464
#[napi]
6565
pub struct EncryptedAttachment {
6666
media_encryption_info: matrix_sdk_crypto::MediaEncryptionInfo,
67-
encrypted_data: Uint8Array,
67+
68+
/// The actual encrypted data.
69+
pub encrypted_data: Uint8Array,
6870
}
6971

7072
#[napi]
@@ -93,14 +95,4 @@ impl EncryptedAttachment {
9395
pub fn media_encryption_info(&self) -> String {
9496
serde_json::to_string(&self.media_encryption_info).unwrap()
9597
}
96-
97-
/// Return a **copy** of the encrypted data in a new `Uint8Array`.
98-
///
99-
/// We are aware this is not ideal to copy the value, but the
100-
/// current available Node.js API does seem be limited in that
101-
/// regard.
102-
#[napi(getter)]
103-
pub fn encrypted_data(&self) -> Uint8Array {
104-
Uint8Array::new(self.encrypted_data.deref().to_owned())
105-
}
10698
}

0 commit comments

Comments
 (0)