diff options
author | Maurice Lam <yukl@google.com> | 2023-06-07 01:39:51 +0000 |
---|---|---|
committer | Boringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-08-08 20:10:14 +0000 |
commit | 77d431746df1f86927cf8462533aa5b0f67323a1 (patch) | |
tree | 3a2c7e6114a2036215377f18e94a7a4a78e6ff93 /rust | |
parent | 5d9ffb810b2c5c7aaa6700161989d19547983b5f (diff) | |
download | boringssl-77d431746df1f86927cf8462533aa5b0f67323a1.zip boringssl-77d431746df1f86927cf8462533aa5b0f67323a1.tar.gz boringssl-77d431746df1f86927cf8462533aa5b0f67323a1.tar.bz2 |
Fix FFI slice usage
Use CSlice instead of a regular Rust slice when passing pointers to C
FFI.
Change-Id: Iccd827f4c6f005d860993e97fef5e9caf514885b
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60525
Reviewed-by: David Benjamin <davidben@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Diffstat (limited to 'rust')
-rw-r--r-- | rust/bssl-crypto/src/digest.rs | 7 | ||||
-rw-r--r-- | rust/bssl-crypto/src/ed25519.rs | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/rust/bssl-crypto/src/digest.rs b/rust/bssl-crypto/src/digest.rs index 35b6534..aa6355d 100644 --- a/rust/bssl-crypto/src/digest.rs +++ b/rust/bssl-crypto/src/digest.rs @@ -15,7 +15,7 @@ use core::marker::PhantomData; -use crate::ForeignTypeRef; +use crate::{ForeignTypeRef, CSlice}; /// The SHA-256 digest algorithm. #[derive(Clone)] @@ -110,10 +110,11 @@ impl<M: Md, const OUTPUT_SIZE: usize> Digest<M, OUTPUT_SIZE> { /// Hashes the provided input into the current digest operation. pub fn update(&mut self, data: &[u8]) { + let data_ffi = CSlice(data); // Safety: - // - `data` is a slice from safe Rust. + // - `data` is a CSlice from safe Rust. let result = unsafe { - bssl_sys::EVP_DigestUpdate(&mut self.0, data.as_ptr() as *const _, data.len()) + bssl_sys::EVP_DigestUpdate(&mut self.0, data_ffi.as_ptr() as *const _, data_ffi.len()) }; assert_eq!(result, 1, "bssl_sys::EVP_DigestUpdate failed"); } diff --git a/rust/bssl-crypto/src/ed25519.rs b/rust/bssl-crypto/src/ed25519.rs index df36507..f4ab5be 100644 --- a/rust/bssl-crypto/src/ed25519.rs +++ b/rust/bssl-crypto/src/ed25519.rs @@ -89,14 +89,15 @@ impl PrivateKey { pub fn sign(&self, msg: &[u8]) -> Signature { let mut sig_bytes = [0u8; SIGNATURE_LENGTH]; + let msg_ffi = CSlice(msg); // Safety: // - On allocation failure we panic. // - Signature and private keys are always the correct length. let result = unsafe { bssl_sys::ED25519_sign( sig_bytes.as_mut_ptr(), - msg.as_ptr(), - msg.len(), + msg_ffi.as_ptr(), + msg_ffi.len(), self.0.as_ptr(), ) }; |