Skip to content

Commit

Permalink
Merge #555: Backport and bump version to 0.22.2
Browse files Browse the repository at this point in the history
12e67f1 Bump version to 0.22.2 (Tobin C. Harding)
7604f32 Add saftey docs for PreallocatedContext trait (Tobin C. Harding)
357e800 context: introduce unsafe `PreallocatedContext` trait (Andrew Poelstra)

Pull request description:

  Backport #548 and bump version ready for release.

ACKs for top commit:
  Kixunil:
    ACK 12e67f1

Tree-SHA512: 6e2e700ecede75b00a6629e314f814946d4a929e5a5b1540b663cf5b338dae4fa7eda293dd6877888976892c834eb63a53ce29938d451e6062ed3d6db3ad6429
  • Loading branch information
apoelstra committed Dec 7, 2022
2 parents de65fb2 + 12e67f1 commit 073521c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
# 0.22.2 - 2022-12-05

* Backport [fix soundness issue with `preallocated_gen_new`](https://github.com/rust-bitcoin/rust-secp256k1/pull/548)

# 0.22.1 - 2022-03-10

* [Reintroduce](https://github.com/rust-bitcoin/rust-secp256k1/pull/417) accidentally removed possibility to create `SharedSecret` from byte serialization
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.22.1"
version = "0.22.2"
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
"Andrew Poelstra <apoelstra@wpsoftware.net>" ]
license = "CC0-1.0"
Expand Down
18 changes: 16 additions & 2 deletions src/context.rs
Expand Up @@ -299,8 +299,22 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
}
}

impl<'buf, C: Context + 'buf> Secp256k1<C> {
/// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all)
/// Trait marking that a particular context object internally points to
/// memory that must outlive `'a`
///
/// # Safety
///
/// This trait is used internally to gate which context markers can safely
/// be used with the `preallocated_gen_new` function. Do not implement it
/// on your own structures.
pub unsafe trait PreallocatedContext<'a> {}

unsafe impl<'buf> PreallocatedContext<'buf> for AllPreallocated<'buf> {}
unsafe impl<'buf> PreallocatedContext<'buf> for SignOnlyPreallocated<'buf> {}
unsafe impl<'buf> PreallocatedContext<'buf> for VerifyOnlyPreallocated<'buf> {}

impl<'buf, C: Context + PreallocatedContext<'buf>> Secp256k1<C> {
/// Lets you create a context with a preallocated buffer in a generic manner (sign/verify/all).
pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result<Secp256k1<C>, Error> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();
Expand Down

0 comments on commit 073521c

Please sign in to comment.