From f1e1da12139a70674f267ce775effd960844a6a5 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Sun, 25 Oct 2015 18:26:08 -0500 Subject: [PATCH] Update for breaking changes in underlying rustc. This should be a major version number since I changed public constants in the ffi module. I'm not doing so as the invariant "will the constants be meaningful to the underlying library" has not changed. In general this library's version numbers do not map well to the underlying library, which is as-yet not versioned at all, so users need to always be running "the lastest" rust-secp256k1 anyway, and semantic versioning can't really be used meaninfully. So this is a bit of a judgement call. --- Cargo.toml | 2 +- src/ffi.rs | 10 ++++++++-- src/key.rs | 3 ++- src/lib.rs | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 57af8f9..a7aef3b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "secp256k1" -version = "0.3.2" +version = "0.3.3" authors = [ "Dawid Ciężarkiewicz ", "Andrew Poelstra " ] license = "CC0-1.0" diff --git a/src/ffi.rs b/src/ffi.rs index 7ed3fe4..bd7ed4d 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -19,10 +19,16 @@ use std::mem; use libc::{c_int, c_uchar, c_uint, c_void, size_t}; +/// Flag for context to enable no precomputation +pub const SECP256K1_START_NONE: c_uint = (1 << 0) | 0; /// Flag for context to enable verification precomputation -pub const SECP256K1_START_VERIFY: c_uint = 0x1; +pub const SECP256K1_START_VERIFY: c_uint = (1 << 0) | (1 << 8); /// Flag for context to enable signing precomputation -pub const SECP256K1_START_SIGN: c_uint = 0x2; +pub const SECP256K1_START_SIGN: c_uint = (1 << 0) | (1 << 9); +/// Flag for keys to indicate uncompressed serialization format +pub const SECP256K1_SER_UNCOMPRESSED: c_uint = (1 << 1) | 0; +/// Flag for keys to indicate compressed serialization format +pub const SECP256K1_SER_COMPRESSED: c_uint = (1 << 1) | (1 << 8); /// A nonce generation function. Ordinary users of the library /// never need to see this type; only if you need to control diff --git a/src/key.rs b/src/key.rs index 4a2eac1..46672de 100644 --- a/src/key.rs +++ b/src/key.rs @@ -160,9 +160,10 @@ impl PublicKey { unsafe { let mut ret_len = ret.len() as ::libc::size_t; + let compressed = if compressed { ffi::SECP256K1_SER_COMPRESSED } else { ffi::SECP256K1_SER_UNCOMPRESSED }; debug_assert!(ffi::secp256k1_ec_pubkey_serialize(secp.ctx, ret.as_ptr(), &mut ret_len, self.as_ptr(), - if compressed {1} else {0}) == 1); + compressed) == 1); ret.set_len(ret_len as usize); } ret diff --git a/src/lib.rs b/src/lib.rs index 459e3ca..a197fb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -356,7 +356,7 @@ impl Secp256k1 { /// Creates a new Secp256k1 context with the specified capabilities pub fn with_caps(caps: ContextFlag) -> Secp256k1 { let flag = match caps { - ContextFlag::None => 0, + ContextFlag::None => ffi::SECP256K1_START_NONE, ContextFlag::SignOnly => ffi::SECP256K1_START_SIGN, ContextFlag::VerifyOnly => ffi::SECP256K1_START_VERIFY, ContextFlag::Full => ffi::SECP256K1_START_SIGN | ffi::SECP256K1_START_VERIFY