Update to serde 1.0/bincode 0.8.

This commit is contained in:
Sean Bowe 2017-05-07 10:24:54 -06:00
parent a98e84e09a
commit d95a9b0b29
3 changed files with 54 additions and 54 deletions

@ -11,9 +11,9 @@ version = "0.0.2"
[dependencies] [dependencies]
rand = "0.3.*" rand = "0.3.*"
byteorder = "1.*" byteorder = "1.*"
serde = "0.9.*" serde = "1.0"
crossbeam = "0.2" crossbeam = "0.2"
num_cpus = "1.0" num_cpus = "1.0"
[dev-dependencies.bincode] [dev-dependencies]
git = "https://github.com/TyOverby/bincode.git" bincode = "0.8.0"

@ -17,8 +17,8 @@ use super::{
Cow Cow
}; };
use serde::ser::{Serialize, Serializer, SerializeSeq}; use serde::ser::{Serialize, Serializer, SerializeTuple};
use serde::de::{Deserialize, Deserializer, Visitor, SeqVisitor, Error}; use serde::de::{Deserialize, Deserializer, Visitor, SeqAccess, Error};
#[macro_use] #[macro_use]
mod fp; mod fp;
@ -105,7 +105,7 @@ impl Serialize for G1PointData {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer where S: Serializer
{ {
let mut seq = serializer.serialize_seq_fixed_size(96)?; let mut seq = serializer.serialize_tuple(96)?;
for i in self.0.iter() { for i in self.0.iter() {
seq.serialize_element(i)?; seq.serialize_element(i)?;
} }
@ -113,28 +113,28 @@ impl Serialize for G1PointData {
} }
} }
impl Deserialize for G1PointData { impl<'a> Deserialize<'a> for G1PointData {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer where D: Deserializer<'a>
{ {
struct G1PointVisitor; struct G1PointVisitor;
impl Visitor for G1PointVisitor { impl<'a> Visitor<'a> for G1PointVisitor {
type Value = G1PointData; type Value = G1PointData;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "expected 96-byte G1 point X, Y coordinates") write!(formatter, "expected 96-byte G1 point X, Y coordinates")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where V: SeqVisitor where A: SeqAccess<'a>
{ {
let mut tmp = [0; 96]; let mut tmp = [0; 96];
for i in &mut tmp[..] { for i in &mut tmp[..] {
if let Some(v) = visitor.visit()? { if let Some(v) = seq.next_element()? {
*i = v; *i = v;
} else { } else {
return Err(V::Error::custom("not enough bytes")) return Err(A::Error::custom("not enough bytes"))
} }
} }
@ -142,7 +142,7 @@ impl Deserialize for G1PointData {
} }
} }
deserializer.deserialize_seq_fixed_size(96, G1PointVisitor) deserializer.deserialize_tuple(96, G1PointVisitor)
} }
} }
@ -150,7 +150,7 @@ impl Serialize for G2PointData {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer where S: Serializer
{ {
let mut seq = serializer.serialize_seq_fixed_size(192)?; let mut seq = serializer.serialize_tuple(192)?;
for i in self.0.iter() { for i in self.0.iter() {
seq.serialize_element(i)?; seq.serialize_element(i)?;
} }
@ -158,28 +158,28 @@ impl Serialize for G2PointData {
} }
} }
impl Deserialize for G2PointData { impl<'a> Deserialize<'a> for G2PointData {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer where D: Deserializer<'a>
{ {
struct G2PointVisitor; struct G2PointVisitor;
impl Visitor for G2PointVisitor { impl<'a> Visitor<'a> for G2PointVisitor {
type Value = G2PointData; type Value = G2PointData;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "expected 192-byte G2 point X, Y coordinates") write!(formatter, "expected 192-byte G2 point X, Y coordinates")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where V: SeqVisitor where A: SeqAccess<'a>
{ {
let mut tmp = [0; 192]; let mut tmp = [0; 192];
for i in &mut tmp[..] { for i in &mut tmp[..] {
if let Some(v) = visitor.visit()? { if let Some(v) = seq.next_element()? {
*i = v; *i = v;
} else { } else {
return Err(V::Error::custom("not enough bytes")) return Err(A::Error::custom("not enough bytes"))
} }
} }
@ -187,7 +187,7 @@ impl Deserialize for G2PointData {
} }
} }
deserializer.deserialize_seq_fixed_size(192, G2PointVisitor) deserializer.deserialize_tuple(192, G2PointVisitor)
} }
} }
@ -204,15 +204,15 @@ impl Serialize for G1Uncompressed {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer where S: Serializer
{ {
let mut tup = serializer.serialize_tuple(2)?;
match *self { match *self {
G1Uncompressed::Infinity => { G1Uncompressed::Infinity => {
let mut tup = serializer.serialize_seq_fixed_size(2)?;
tup.serialize_element(&0u8)?; tup.serialize_element(&0u8)?;
tup.serialize_element(&())?; tup.serialize_element(&())?;
tup.end() tup.end()
}, },
G1Uncompressed::Point(ref v) => { G1Uncompressed::Point(ref v) => {
let mut tup = serializer.serialize_seq_fixed_size(2)?;
tup.serialize_element(&4u8)?; tup.serialize_element(&4u8)?;
tup.serialize_element(v)?; tup.serialize_element(v)?;
tup.end() tup.end()
@ -221,49 +221,49 @@ impl Serialize for G1Uncompressed {
} }
} }
impl Deserialize for G1Uncompressed { impl<'a> Deserialize<'a> for G1Uncompressed {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer where D: Deserializer<'a>
{ {
use std::fmt; use std::fmt;
struct G1Visitor; struct G1Visitor;
impl Visitor for G1Visitor { impl<'a> Visitor<'a> for G1Visitor {
type Value = G1Uncompressed; type Value = G1Uncompressed;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "expected uncompressed G1 element") write!(formatter, "expected uncompressed G1 element")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where V: SeqVisitor where A: SeqAccess<'a>
{ {
if let Some(t) = visitor.visit::<u8>()? { if let Some(t) = seq.next_element::<u8>()? {
if t == 0 { if t == 0 {
if let Some(()) = visitor.visit::<()>()? { if let Some(()) = seq.next_element::<()>()? {
Ok(G1Uncompressed::Infinity) Ok(G1Uncompressed::Infinity)
} else { } else {
Err(V::Error::custom("expected null coordinate")) Err(A::Error::custom("expected null coordinate"))
} }
} else if t == 4 { } else if t == 4 {
if let Some(p) = visitor.visit::<G1PointData>()? { if let Some(p) = seq.next_element::<G1PointData>()? {
Ok(G1Uncompressed::Point(p)) Ok(G1Uncompressed::Point(p))
} else { } else {
Err(V::Error::custom("expected X, Y coordinate")) Err(A::Error::custom("expected X, Y coordinate"))
} }
} else { } else {
Err(V::Error::custom("expected IEEE prefix for uncompressed G1 element")) Err(A::Error::custom("expected IEEE prefix for uncompressed G1 element"))
} }
} else { } else {
Err(V::Error::custom("expected IEEE prefix for uncompressed G1 element")) Err(A::Error::custom("expected IEEE prefix for uncompressed G1 element"))
} }
} }
} }
let v = G1Visitor; let v = G1Visitor;
deserializer.deserialize_seq_fixed_size(2, v) deserializer.deserialize_tuple(2, v)
} }
} }
@ -271,15 +271,15 @@ impl Serialize for G2Uncompressed {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer where S: Serializer
{ {
let mut tup = serializer.serialize_tuple(2)?;
match *self { match *self {
G2Uncompressed::Infinity => { G2Uncompressed::Infinity => {
let mut tup = serializer.serialize_seq_fixed_size(2)?;
tup.serialize_element(&0u8)?; tup.serialize_element(&0u8)?;
tup.serialize_element(&())?; tup.serialize_element(&())?;
tup.end() tup.end()
}, },
G2Uncompressed::Point(ref v) => { G2Uncompressed::Point(ref v) => {
let mut tup = serializer.serialize_seq_fixed_size(2)?;
tup.serialize_element(&4u8)?; tup.serialize_element(&4u8)?;
tup.serialize_element(v)?; tup.serialize_element(v)?;
tup.end() tup.end()
@ -288,49 +288,49 @@ impl Serialize for G2Uncompressed {
} }
} }
impl Deserialize for G2Uncompressed { impl<'a> Deserialize<'a> for G2Uncompressed {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer where D: Deserializer<'a>
{ {
use std::fmt; use std::fmt;
struct G2Visitor; struct G2Visitor;
impl Visitor for G2Visitor { impl<'a> Visitor<'a> for G2Visitor {
type Value = G2Uncompressed; type Value = G2Uncompressed;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "expected uncompressed G2 element") write!(formatter, "expected uncompressed G2 element")
} }
fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error> fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where V: SeqVisitor where A: SeqAccess<'a>
{ {
if let Some(t) = visitor.visit::<u8>()? { if let Some(t) = seq.next_element::<u8>()? {
if t == 0 { if t == 0 {
if let Some(()) = visitor.visit::<()>()? { if let Some(()) = seq.next_element::<()>()? {
Ok(G2Uncompressed::Infinity) Ok(G2Uncompressed::Infinity)
} else { } else {
Err(V::Error::custom("expected null coordinate")) Err(A::Error::custom("expected null coordinate"))
} }
} else if t == 4 { } else if t == 4 {
if let Some(p) = visitor.visit::<G2PointData>()? { if let Some(p) = seq.next_element::<G2PointData>()? {
Ok(G2Uncompressed::Point(p)) Ok(G2Uncompressed::Point(p))
} else { } else {
Err(V::Error::custom("expected X, Y coordinate")) Err(A::Error::custom("expected X, Y coordinate"))
} }
} else { } else {
Err(V::Error::custom("expected IEEE prefix for uncompressed G2 element")) Err(A::Error::custom("expected IEEE prefix for uncompressed G2 element"))
} }
} else { } else {
Err(V::Error::custom("expected IEEE prefix for uncompressed G2 element")) Err(A::Error::custom("expected IEEE prefix for uncompressed G2 element"))
} }
} }
} }
let v = G2Visitor; let v = G2Visitor;
deserializer.deserialize_seq_fixed_size(2, v) deserializer.deserialize_tuple(2, v)
} }
} }

@ -106,7 +106,7 @@ pub trait GroupAffine<E: Engine, G: Group<E>>: Copy +
fn to_uncompressed(&self, &E) -> Self::Uncompressed; fn to_uncompressed(&self, &E) -> Self::Uncompressed;
} }
pub trait GroupRepresentation<E: Engine, G: Group<E>>: Serialize + Deserialize pub trait GroupRepresentation<E: Engine, G: Group<E>>: Serialize + for<'a> Deserialize<'a>
{ {
/// If the point representation is valid (lies on the curve, correct /// If the point representation is valid (lies on the curve, correct
/// subgroup) this function will return it. /// subgroup) this function will return it.