-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from Foundation-Devices/jeandudey/sft-3616-fi…
…x-rust-warnings SFT-3616: Fix Rust warnings
- Loading branch information
Showing
4 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// SPDX-FileCopyrightText: © 2023 Foundation Devices, Inc. <[email protected]> | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
use core::ptr; | ||
use once_cell::sync::Lazy; | ||
use secp256k1::{ | ||
ffi::types::AlignedType, AllPreallocated, KeyPair, Message, Secp256k1, | ||
|
@@ -12,7 +13,13 @@ static mut PRE_ALLOCATED_CTX_BUF: [AlignedType; 20] = [AlignedType::ZERO; 20]; | |
/// cbindgen:ignore | ||
static PRE_ALLOCATED_CTX: Lazy<Secp256k1<AllPreallocated<'static>>> = | ||
Lazy::new(|| { | ||
let buf = unsafe { &mut PRE_ALLOCATED_CTX_BUF }; | ||
// SAFETY: | ||
// | ||
// This pre-allocated buffer safety depends on trusting libsecp256k1 | ||
// that it writes the context buffer only once for initialization and | ||
// then only performs reads to it. | ||
let buf = unsafe { &mut *ptr::addr_of_mut!(PRE_ALLOCATED_CTX_BUF) }; | ||
|
||
Secp256k1::preallocated_new(buf) | ||
.expect("the pre-allocated context buf should have enough space") | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters