Update for newest Cargo
This commit is contained in:
parent
05406515b8
commit
4c9f47e108
|
@ -1,10 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "secp256k1"
|
name = "bitcoin-secp256k1-rs"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = [
|
authors = [
|
||||||
"Dawid Ciężarkiewicz <dpc@ucore.info>"
|
"Dawid Ciężarkiewicz <dpc@ucore.info>"
|
||||||
]
|
]
|
||||||
|
|
||||||
[[lib]]
|
[[lib]]
|
||||||
name = "secp256k1"
|
name = "bitcoin-secp256k1-rs"
|
||||||
|
path = "src/secp256k1.rs"
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![crate_type = "rlib"]
|
#![crate_type = "rlib"]
|
||||||
#![crate_type = "dylib"]
|
#![crate_type = "dylib"]
|
||||||
#![crate_id = "github.com/dpc/bitcoin-secp256k1-rs#secp256k1:0.1"]
|
#![crate_name = "bitcoin-secp256k1-rs"]
|
||||||
#![comment = "Bindings and wrapper functions for bitcoin secp256k1 library."]
|
#![comment = "Bindings and wrapper functions for bitcoin secp256k1 library."]
|
||||||
|
#![feature(phase)]
|
||||||
|
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate sync;
|
extern crate sync;
|
||||||
|
@ -134,7 +136,7 @@ impl Secp256k1 {
|
||||||
|
|
||||||
let res = unsafe {
|
let res = unsafe {
|
||||||
secp256k1_ecdsa_sign(
|
secp256k1_ecdsa_sign(
|
||||||
msg.as_ptr(), msg.len() as i32,
|
msg.as_ptr(), msg.len() as c_int,
|
||||||
sig.as_mut_ptr(), &mut siglen,
|
sig.as_mut_ptr(), &mut siglen,
|
||||||
seckey.as_ptr(),
|
seckey.as_ptr(),
|
||||||
nonce.as_ptr()
|
nonce.as_ptr()
|
||||||
|
@ -154,7 +156,7 @@ impl Secp256k1 {
|
||||||
|
|
||||||
pub fn sign_compact(
|
pub fn sign_compact(
|
||||||
&self,
|
&self,
|
||||||
sig : &mut Signature,
|
sig : &mut [u8],
|
||||||
msg : &[u8],
|
msg : &[u8],
|
||||||
seckey : &SecKey,
|
seckey : &SecKey,
|
||||||
nonce : &Nonce
|
nonce : &Nonce
|
||||||
|
@ -170,7 +172,7 @@ impl Secp256k1 {
|
||||||
|
|
||||||
let res = unsafe {
|
let res = unsafe {
|
||||||
secp256k1_ecdsa_sign_compact(
|
secp256k1_ecdsa_sign_compact(
|
||||||
msg.as_ptr(), msg.len() as i32,
|
msg.as_ptr(), msg.len() as c_int,
|
||||||
sig.as_mut_ptr(),
|
sig.as_mut_ptr(),
|
||||||
seckey.as_ptr(),
|
seckey.as_ptr(),
|
||||||
nonce.as_ptr(),
|
nonce.as_ptr(),
|
||||||
|
@ -188,7 +190,7 @@ impl Secp256k1 {
|
||||||
pub fn recover_compact(
|
pub fn recover_compact(
|
||||||
&self,
|
&self,
|
||||||
msg : &[u8],
|
msg : &[u8],
|
||||||
sig : &Signature,
|
sig : &[u8],
|
||||||
pubkey : &mut PubKey,
|
pubkey : &mut PubKey,
|
||||||
recid : i32
|
recid : i32
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
@ -225,7 +227,7 @@ impl Secp256k1 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn verify(&self, msg : &[u8], sig : &Signature, pubkey : &PubKey) -> VerifyResult {
|
pub fn verify(&self, msg : &[u8], sig : &[u8], pubkey : &PubKey) -> VerifyResult {
|
||||||
|
|
||||||
let (pub_ptr, pub_len) = match *pubkey {
|
let (pub_ptr, pub_len) = match *pubkey {
|
||||||
Uncompressed(ref key) => (key.as_ptr(), key.len()),
|
Uncompressed(ref key) => (key.as_ptr(), key.len()),
|
||||||
|
@ -260,7 +262,7 @@ fn invalid_pubkey() {
|
||||||
|
|
||||||
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_mut_slice(), &sig, &pubkey), Err(InvalidPublicKey));
|
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidPublicKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -275,7 +277,7 @@ fn valid_pubkey_uncompressed() {
|
||||||
|
|
||||||
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_mut_slice(), &sig, &pubkey), Err(InvalidSignature));
|
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidSignature));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -290,7 +292,7 @@ fn valid_pubkey_compressed() {
|
||||||
|
|
||||||
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_mut_slice(), &sig, &pubkey), Err(InvalidSignature));
|
assert_eq!(s.verify(msg.as_mut_slice(), sig.as_slice(), &pubkey), Err(InvalidSignature));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -325,7 +327,7 @@ fn sign_and_verify() {
|
||||||
|
|
||||||
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_slice(), &sig, &pubkey), Ok(true));
|
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -345,7 +347,7 @@ fn sign_and_verify_fail() {
|
||||||
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
s.sign(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
||||||
|
|
||||||
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
rand::task_rng().fill_bytes(msg.as_mut_slice());
|
||||||
assert_eq!(s.verify(msg.as_slice(), &sig, &pubkey), Ok(false));
|
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -363,9 +365,9 @@ fn sign_compact() {
|
||||||
|
|
||||||
s.pubkey_create(&mut pubkey, &seckey).unwrap();
|
s.pubkey_create(&mut pubkey, &seckey).unwrap();
|
||||||
|
|
||||||
let _ = s.sign_compact(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
let _ = s.sign_compact(sig.as_mut_slice(), msg.as_slice(), &seckey, &nonce).unwrap();
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_slice(), &sig, &pubkey), Ok(true));
|
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -383,11 +385,11 @@ fn sign_compact_with_recovery() {
|
||||||
|
|
||||||
s.pubkey_create(&mut pubkey, &seckey).unwrap();
|
s.pubkey_create(&mut pubkey, &seckey).unwrap();
|
||||||
|
|
||||||
let recid = s.sign_compact(&mut sig, msg.as_slice(), &seckey, &nonce).unwrap();
|
let recid = s.sign_compact(sig.as_mut_slice(), msg.as_slice(), &seckey, &nonce).unwrap();
|
||||||
|
|
||||||
s.recover_compact(msg.as_slice(), &sig, &mut pubkey, recid).unwrap();
|
s.recover_compact(msg.as_slice(), sig.as_slice(), &mut pubkey, recid).unwrap();
|
||||||
|
|
||||||
assert_eq!(s.verify(msg.as_slice(), &sig, &pubkey), Ok(true));
|
assert_eq!(s.verify(msg.as_slice(), sig.as_slice(), &pubkey), Ok(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue