IoResult -> io::Result, copy_nonoverlapping_memory -> copy_nonoverlapping
This commit is contained in:
parent
1e24549ef5
commit
d0519f0b3a
32
src/key.rs
32
src/key.rs
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
//! Public/Private keys
|
//! Public/Private keys
|
||||||
|
|
||||||
use std::intrinsics::copy_nonoverlapping_memory;
|
use std::intrinsics::copy_nonoverlapping;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rand::Rng;
|
use std::rand::Rng;
|
||||||
|
@ -67,9 +67,9 @@ fn random_32_bytes<R:Rng>(rng: &mut R) -> [u8; 32] {
|
||||||
fn bits2octets(data: &[u8]) -> [u8; 32] {
|
fn bits2octets(data: &[u8]) -> [u8; 32] {
|
||||||
let mut ret = [0; 32];
|
let mut ret = [0; 32];
|
||||||
unsafe {
|
unsafe {
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
cmp::min(data.len(), 32));
|
cmp::min(data.len(), 32));
|
||||||
}
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
@ -88,9 +88,9 @@ impl Nonce {
|
||||||
constants::NONCE_SIZE => {
|
constants::NONCE_SIZE => {
|
||||||
let mut ret = [0; constants::NONCE_SIZE];
|
let mut ret = [0; constants::NONCE_SIZE];
|
||||||
unsafe {
|
unsafe {
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
data.len());
|
data.len());
|
||||||
}
|
}
|
||||||
Ok(Nonce(ret))
|
Ok(Nonce(ret))
|
||||||
}
|
}
|
||||||
|
@ -182,9 +182,9 @@ impl SecretKey {
|
||||||
if ffi::secp256k1_ec_seckey_verify(data.as_ptr()) == 0 {
|
if ffi::secp256k1_ec_seckey_verify(data.as_ptr()) == 0 {
|
||||||
return Err(InvalidSecretKey);
|
return Err(InvalidSecretKey);
|
||||||
}
|
}
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
data.len());
|
data.len());
|
||||||
}
|
}
|
||||||
Ok(SecretKey(ret))
|
Ok(SecretKey(ret))
|
||||||
}
|
}
|
||||||
|
@ -276,18 +276,18 @@ impl PublicKey {
|
||||||
data.len() as ::libc::c_int) == 0 {
|
data.len() as ::libc::c_int) == 0 {
|
||||||
return Err(InvalidPublicKey);
|
return Err(InvalidPublicKey);
|
||||||
}
|
}
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
data.len());
|
data.len());
|
||||||
}
|
}
|
||||||
Ok(PublicKey(PublicKeyData::Compressed(ret)))
|
Ok(PublicKey(PublicKeyData::Compressed(ret)))
|
||||||
}
|
}
|
||||||
constants::UNCOMPRESSED_PUBLIC_KEY_SIZE => {
|
constants::UNCOMPRESSED_PUBLIC_KEY_SIZE => {
|
||||||
let mut ret = [0; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE];
|
let mut ret = [0; constants::UNCOMPRESSED_PUBLIC_KEY_SIZE];
|
||||||
unsafe {
|
unsafe {
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
data.len());
|
data.len());
|
||||||
}
|
}
|
||||||
Ok(PublicKey(PublicKeyData::Uncompressed(ret)))
|
Ok(PublicKey(PublicKeyData::Uncompressed(ret)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,12 +79,12 @@ macro_rules! impl_array_newtype {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> $thing {
|
fn clone(&self) -> $thing {
|
||||||
unsafe {
|
unsafe {
|
||||||
use std::intrinsics::copy_nonoverlapping_memory;
|
use std::intrinsics::copy_nonoverlapping;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
let mut ret: $thing = mem::uninitialized();
|
let mut ret: $thing = mem::uninitialized();
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
self.as_ptr(),
|
self.as_ptr(),
|
||||||
mem::size_of::<$thing>());
|
mem::size_of::<$thing>());
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ extern crate libc;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
||||||
use std::intrinsics::copy_nonoverlapping_memory;
|
use std::intrinsics::copy_nonoverlapping;
|
||||||
use std::io::IoResult;
|
use std::io;
|
||||||
use std::rand::{OsRng, Rng, SeedableRng};
|
use std::rand::{OsRng, Rng, SeedableRng};
|
||||||
use std::sync::{Once, ONCE_INIT};
|
use std::sync::{Once, ONCE_INIT};
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
|
@ -103,9 +103,9 @@ impl Signature {
|
||||||
if data.len() <= constants::MAX_SIGNATURE_SIZE {
|
if data.len() <= constants::MAX_SIGNATURE_SIZE {
|
||||||
let mut ret = [0; constants::MAX_SIGNATURE_SIZE];
|
let mut ret = [0; constants::MAX_SIGNATURE_SIZE];
|
||||||
unsafe {
|
unsafe {
|
||||||
copy_nonoverlapping_memory(ret.as_mut_ptr(),
|
copy_nonoverlapping(ret.as_mut_ptr(),
|
||||||
data.as_ptr(),
|
data.as_ptr(),
|
||||||
data.len());
|
data.len());
|
||||||
}
|
}
|
||||||
Ok(Signature(data.len(), ret))
|
Ok(Signature(data.len(), ret))
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,7 +158,7 @@ pub fn init() {
|
||||||
|
|
||||||
impl Secp256k1 {
|
impl Secp256k1 {
|
||||||
/// Constructs a new secp256k1 engine.
|
/// Constructs a new secp256k1 engine.
|
||||||
pub fn new() -> IoResult<Secp256k1> {
|
pub fn new() -> io::Result<Secp256k1> {
|
||||||
init();
|
init();
|
||||||
let mut osrng = try!(OsRng::new());
|
let mut osrng = try!(OsRng::new());
|
||||||
let mut seed = [0; 2048];
|
let mut seed = [0; 2048];
|
||||||
|
|
Loading…
Reference in New Issue