Update serde dep to 0.6 from 0.3
This commit is contained in:
parent
016d781f2e
commit
cc68cf8b9e
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "secp256k1"
|
name = "secp256k1"
|
||||||
version = "0.1.2"
|
version = "0.2.2"
|
||||||
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
|
||||||
"Andrew Poelstra <apoelstra@wpsoftware.net>" ]
|
"Andrew Poelstra <apoelstra@wpsoftware.net>" ]
|
||||||
license = "CC0-1.0"
|
license = "CC0-1.0"
|
||||||
|
@ -24,5 +24,6 @@ arrayvec = "0.3"
|
||||||
rand = "0.3"
|
rand = "0.3"
|
||||||
libc = "0.1"
|
libc = "0.1"
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
serde = "0.3"
|
serde = "0.6"
|
||||||
|
serde_json = "0.6"
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use libc::{c_int, c_uchar, c_uint, c_void};
|
use libc::{c_int, c_uchar, c_uint, c_void};
|
||||||
|
|
||||||
|
/// Flag for context to enable verification precomputation
|
||||||
pub const SECP256K1_START_VERIFY: c_uint = 0x1;
|
pub const SECP256K1_START_VERIFY: c_uint = 0x1;
|
||||||
|
/// Flag for context to enable signing precomputation
|
||||||
pub const SECP256K1_START_SIGN: c_uint = 0x2;
|
pub const SECP256K1_START_SIGN: c_uint = 0x2;
|
||||||
|
|
||||||
/// A nonce generation function. Ordinary users of the library
|
/// A nonce generation function. Ordinary users of the library
|
||||||
|
|
26
src/key.rs
26
src/key.rs
|
@ -255,7 +255,7 @@ impl Deserialize for PublicKey {
|
||||||
}
|
}
|
||||||
try!(v.end());
|
try!(v.end());
|
||||||
|
|
||||||
PublicKey::from_slice(&s, &ret[..read_len]).map_err(|_| de::Error::syntax_error())
|
PublicKey::from_slice(&s, &ret[..read_len]).map_err(|e| de::Error::syntax(&e.to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,40 +402,42 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bad_serde_deserialize() {
|
fn test_bad_serde_deserialize() {
|
||||||
use serde::{json, Deserialize};
|
use serde::Deserialize;
|
||||||
|
use json;
|
||||||
|
|
||||||
// Invalid length
|
// Invalid length
|
||||||
let zero31 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
let zero31 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
||||||
let mut json = json::de::Deserializer::new(zero31.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero31.iter().map(|c| Ok(*c)));
|
||||||
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
let mut json = json::de::Deserializer::new(zero31.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero31.iter().map(|c| Ok(*c)));
|
||||||
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
|
|
||||||
let zero32 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
let zero32 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
||||||
let mut json = json::de::Deserializer::new(zero32.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero32.iter().map(|c| Ok(*c)));
|
||||||
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
let mut json = json::de::Deserializer::new(zero32.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero32.iter().map(|c| Ok(*c)));
|
||||||
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_ok());
|
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_ok());
|
||||||
|
|
||||||
// All zeroes pk is invalid
|
// All zeroes pk is invalid
|
||||||
let zero65 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
let zero65 = "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]".as_bytes();
|
||||||
let mut json = json::de::Deserializer::new(zero65.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero65.iter().map(|c| Ok(*c)));
|
||||||
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
let mut json = json::de::Deserializer::new(zero65.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(zero65.iter().map(|c| Ok(*c)));
|
||||||
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
|
|
||||||
// Syntax error
|
// Syntax error
|
||||||
let string = "\"my key\"".as_bytes();
|
let string = "\"my key\"".as_bytes();
|
||||||
let mut json = json::de::Deserializer::new(string.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(string.iter().map(|c| Ok(*c)));
|
||||||
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<PublicKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
let mut json = json::de::Deserializer::new(string.iter().map(|c| Ok(*c))).unwrap();
|
let mut json = json::de::Deserializer::new(string.iter().map(|c| Ok(*c)));
|
||||||
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
assert!(<SecretKey as Deserialize>::deserialize(&mut json).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_serde() {
|
fn test_serialize_serde() {
|
||||||
use serde::{json, Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
use json;
|
||||||
|
|
||||||
macro_rules! round_trip (
|
macro_rules! round_trip (
|
||||||
($var:ident) => ({
|
($var:ident) => ({
|
||||||
|
@ -445,7 +447,7 @@ mod test {
|
||||||
let mut serializer = json::ser::Serializer::new(&mut encoded);
|
let mut serializer = json::ser::Serializer::new(&mut encoded);
|
||||||
start.serialize(&mut serializer).unwrap();
|
start.serialize(&mut serializer).unwrap();
|
||||||
}
|
}
|
||||||
let mut deserializer = json::de::Deserializer::new(encoded.iter().map(|c| Ok(*c))).unwrap();
|
let mut deserializer = json::de::Deserializer::new(encoded.iter().map(|c| Ok(*c)));
|
||||||
let decoded = Deserialize::deserialize(&mut deserializer);
|
let decoded = Deserialize::deserialize(&mut deserializer);
|
||||||
assert_eq!(Some(start), decoded.ok());
|
assert_eq!(Some(start), decoded.ok());
|
||||||
})
|
})
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
extern crate arrayvec;
|
extern crate arrayvec;
|
||||||
extern crate rustc_serialize as serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
|
extern crate serde_json as json;
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
|
@ -163,7 +163,7 @@ macro_rules! impl_array_newtype {
|
||||||
for i in 0..$len {
|
for i in 0..$len {
|
||||||
ret[i] = match try!(v.visit()) {
|
ret[i] = match try!(v.visit()) {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => return Err(::serde::de::Error::end_of_stream_error())
|
None => return Err(::serde::de::Error::end_of_stream())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
try!(v.end());
|
try!(v.end());
|
||||||
|
|
Loading…
Reference in New Issue