From a1fe831501906546af954cbae0f9cff352004948 Mon Sep 17 00:00:00 2001 From: Quentin Le Sceller Date: Thu, 4 Mar 2021 10:28:28 -0500 Subject: [PATCH] [5.0.x] Do not use serde private export (#3544) * Use std instead of serde::export * Fix serde private import --- core/src/ser.rs | 307 +++++++++++++++++++++++------------------------- 1 file changed, 149 insertions(+), 158 deletions(-) diff --git a/core/src/ser.rs b/core/src/ser.rs index eb5af150d2..78bd79c3b0 100644 --- a/core/src/ser.rs +++ b/core/src/ser.rs @@ -27,7 +27,7 @@ use keychain::{BlindingFactor, Identifier, IDENTIFIER_SIZE}; use std::convert::TryInto; use std::fmt::{self, Debug}; use std::io::{self, Read, Write}; -use std::{cmp, error, marker}; +use std::{cmp, error, marker, string}; use util::secp::constants::{ AGG_SIGNATURE_SIZE, COMPRESSED_PUBLIC_KEY_SIZE, MAX_PROOF_SIZE, PEDERSEN_COMMITMENT_SIZE, SECRET_KEY_SIZE, @@ -985,10 +985,7 @@ impl PMMRIndexHashable for T { // serializer for io::Errorkind, originally auto-generated by serde-derive // slightly modified to handle the #[non_exhaustive] tag on io::ErrorKind -fn serialize_error_kind( - kind: &io::ErrorKind, - serializer: S, -) -> serde::export::Result +fn serialize_error_kind(kind: &io::ErrorKind, serializer: S) -> Result where S: serde::Serializer, { @@ -1080,7 +1077,7 @@ where } // deserializer for io::Errorkind, originally auto-generated by serde-derive -fn deserialize_error_kind<'de, D>(deserializer: D) -> serde::export::Result +fn deserialize_error_kind<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, { @@ -1108,100 +1105,97 @@ where struct FieldVisitor; impl<'de> serde::de::Visitor<'de> for FieldVisitor { type Value = Field; - fn expecting( - &self, - formatter: &mut serde::export::Formatter, - ) -> serde::export::fmt::Result { - serde::export::Formatter::write_str(formatter, "variant identifier") + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fmt::Formatter::write_str(formatter, "variant identifier") } - fn visit_u64(self, value: u64) -> serde::export::Result + fn visit_u64(self, value: u64) -> Result where E: serde::de::Error, { match value { - 0u64 => serde::export::Ok(Field::field0), - 1u64 => serde::export::Ok(Field::field1), - 2u64 => serde::export::Ok(Field::field2), - 3u64 => serde::export::Ok(Field::field3), - 4u64 => serde::export::Ok(Field::field4), - 5u64 => serde::export::Ok(Field::field5), - 6u64 => serde::export::Ok(Field::field6), - 7u64 => serde::export::Ok(Field::field7), - 8u64 => serde::export::Ok(Field::field8), - 9u64 => serde::export::Ok(Field::field9), - 10u64 => serde::export::Ok(Field::field10), - 11u64 => serde::export::Ok(Field::field11), - 12u64 => serde::export::Ok(Field::field12), - 13u64 => serde::export::Ok(Field::field13), - 14u64 => serde::export::Ok(Field::field14), - 15u64 => serde::export::Ok(Field::field15), - 16u64 => serde::export::Ok(Field::field16), - 17u64 => serde::export::Ok(Field::field17), - _ => serde::export::Err(serde::de::Error::invalid_value( + 0u64 => Ok(Field::field0), + 1u64 => Ok(Field::field1), + 2u64 => Ok(Field::field2), + 3u64 => Ok(Field::field3), + 4u64 => Ok(Field::field4), + 5u64 => Ok(Field::field5), + 6u64 => Ok(Field::field6), + 7u64 => Ok(Field::field7), + 8u64 => Ok(Field::field8), + 9u64 => Ok(Field::field9), + 10u64 => Ok(Field::field10), + 11u64 => Ok(Field::field11), + 12u64 => Ok(Field::field12), + 13u64 => Ok(Field::field13), + 14u64 => Ok(Field::field14), + 15u64 => Ok(Field::field15), + 16u64 => Ok(Field::field16), + 17u64 => Ok(Field::field17), + _ => Err(serde::de::Error::invalid_value( serde::de::Unexpected::Unsigned(value), &"variant index 0 <= i < 18", )), } } - fn visit_str(self, value: &str) -> serde::export::Result + fn visit_str(self, value: &str) -> Result where E: serde::de::Error, { match value { - "NotFound" => serde::export::Ok(Field::field0), - "PermissionDenied" => serde::export::Ok(Field::field1), - "ConnectionRefused" => serde::export::Ok(Field::field2), - "ConnectionReset" => serde::export::Ok(Field::field3), - "ConnectionAborted" => serde::export::Ok(Field::field4), - "NotConnected" => serde::export::Ok(Field::field5), - "AddrInUse" => serde::export::Ok(Field::field6), - "AddrNotAvailable" => serde::export::Ok(Field::field7), - "BrokenPipe" => serde::export::Ok(Field::field8), - "AlreadyExists" => serde::export::Ok(Field::field9), - "WouldBlock" => serde::export::Ok(Field::field10), - "InvalidInput" => serde::export::Ok(Field::field11), - "InvalidData" => serde::export::Ok(Field::field12), - "TimedOut" => serde::export::Ok(Field::field13), - "WriteZero" => serde::export::Ok(Field::field14), - "Interrupted" => serde::export::Ok(Field::field15), - "Other" => serde::export::Ok(Field::field16), - "UnexpectedEof" => serde::export::Ok(Field::field17), - _ => serde::export::Err(serde::de::Error::unknown_variant(value, VARIANTS)), + "NotFound" => Ok(Field::field0), + "PermissionDenied" => Ok(Field::field1), + "ConnectionRefused" => Ok(Field::field2), + "ConnectionReset" => Ok(Field::field3), + "ConnectionAborted" => Ok(Field::field4), + "NotConnected" => Ok(Field::field5), + "AddrInUse" => Ok(Field::field6), + "AddrNotAvailable" => Ok(Field::field7), + "BrokenPipe" => Ok(Field::field8), + "AlreadyExists" => Ok(Field::field9), + "WouldBlock" => Ok(Field::field10), + "InvalidInput" => Ok(Field::field11), + "InvalidData" => Ok(Field::field12), + "TimedOut" => Ok(Field::field13), + "WriteZero" => Ok(Field::field14), + "Interrupted" => Ok(Field::field15), + "Other" => Ok(Field::field16), + "UnexpectedEof" => Ok(Field::field17), + _ => Err(serde::de::Error::unknown_variant(value, VARIANTS)), } } - fn visit_bytes(self, value: &[u8]) -> serde::export::Result + fn visit_bytes(self, value: &[u8]) -> Result where E: serde::de::Error, { match value { - b"NotFound" => serde::export::Ok(Field::field0), - b"PermissionDenied" => serde::export::Ok(Field::field1), - b"ConnectionRefused" => serde::export::Ok(Field::field2), - b"ConnectionReset" => serde::export::Ok(Field::field3), - b"ConnectionAborted" => serde::export::Ok(Field::field4), - b"NotConnected" => serde::export::Ok(Field::field5), - b"AddrInUse" => serde::export::Ok(Field::field6), - b"AddrNotAvailable" => serde::export::Ok(Field::field7), - b"BrokenPipe" => serde::export::Ok(Field::field8), - b"AlreadyExists" => serde::export::Ok(Field::field9), - b"WouldBlock" => serde::export::Ok(Field::field10), - b"InvalidInput" => serde::export::Ok(Field::field11), - b"InvalidData" => serde::export::Ok(Field::field12), - b"TimedOut" => serde::export::Ok(Field::field13), - b"WriteZero" => serde::export::Ok(Field::field14), - b"Interrupted" => serde::export::Ok(Field::field15), - b"Other" => serde::export::Ok(Field::field16), - b"UnexpectedEof" => serde::export::Ok(Field::field17), + b"NotFound" => Ok(Field::field0), + b"PermissionDenied" => Ok(Field::field1), + b"ConnectionRefused" => Ok(Field::field2), + b"ConnectionReset" => Ok(Field::field3), + b"ConnectionAborted" => Ok(Field::field4), + b"NotConnected" => Ok(Field::field5), + b"AddrInUse" => Ok(Field::field6), + b"AddrNotAvailable" => Ok(Field::field7), + b"BrokenPipe" => Ok(Field::field8), + b"AlreadyExists" => Ok(Field::field9), + b"WouldBlock" => Ok(Field::field10), + b"InvalidInput" => Ok(Field::field11), + b"InvalidData" => Ok(Field::field12), + b"TimedOut" => Ok(Field::field13), + b"WriteZero" => Ok(Field::field14), + b"Interrupted" => Ok(Field::field15), + b"Other" => Ok(Field::field16), + b"UnexpectedEof" => Ok(Field::field17), _ => { - let value = &serde::export::from_utf8_lossy(value); - serde::export::Err(serde::de::Error::unknown_variant(value, VARIANTS)) + let value = &string::String::from_utf8_lossy(value); + Err(serde::de::Error::unknown_variant(value, VARIANTS)) } } } } impl<'de> serde::Deserialize<'de> for Field { #[inline] - fn deserialize(deserializer: D) -> serde::export::Result + fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { @@ -1209,188 +1203,185 @@ where } } struct Visitor<'de> { - marker: serde::export::PhantomData, - lifetime: serde::export::PhantomData<&'de ()>, + marker: marker::PhantomData, + lifetime: marker::PhantomData<&'de ()>, } impl<'de> serde::de::Visitor<'de> for Visitor<'de> { type Value = io::ErrorKind; - fn expecting( - &self, - formatter: &mut serde::export::Formatter, - ) -> serde::export::fmt::Result { - serde::export::Formatter::write_str(formatter, "enum io::ErrorKind") + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fmt::Formatter::write_str(formatter, "enum io::ErrorKind") } - fn visit_enum(self, data: A) -> serde::export::Result + fn visit_enum(self, data: A) -> Result where A: serde::de::EnumAccess<'de>, { match match serde::de::EnumAccess::variant(data) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } } { (Field::field0, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::NotFound) + Ok(io::ErrorKind::NotFound) } (Field::field1, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::PermissionDenied) + Ok(io::ErrorKind::PermissionDenied) } (Field::field2, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::ConnectionRefused) + Ok(io::ErrorKind::ConnectionRefused) } (Field::field3, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::ConnectionReset) + Ok(io::ErrorKind::ConnectionReset) } (Field::field4, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::ConnectionAborted) + Ok(io::ErrorKind::ConnectionAborted) } (Field::field5, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::NotConnected) + Ok(io::ErrorKind::NotConnected) } (Field::field6, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::AddrInUse) + Ok(io::ErrorKind::AddrInUse) } (Field::field7, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::AddrNotAvailable) + Ok(io::ErrorKind::AddrNotAvailable) } (Field::field8, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::BrokenPipe) + Ok(io::ErrorKind::BrokenPipe) } (Field::field9, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::AlreadyExists) + Ok(io::ErrorKind::AlreadyExists) } (Field::field10, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::WouldBlock) + Ok(io::ErrorKind::WouldBlock) } (Field::field11, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::InvalidInput) + Ok(io::ErrorKind::InvalidInput) } (Field::field12, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::InvalidData) + Ok(io::ErrorKind::InvalidData) } (Field::field13, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::TimedOut) + Ok(io::ErrorKind::TimedOut) } (Field::field14, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::WriteZero) + Ok(io::ErrorKind::WriteZero) } (Field::field15, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::Interrupted) + Ok(io::ErrorKind::Interrupted) } (Field::field16, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::Other) + Ok(io::ErrorKind::Other) } (Field::field17, variant) => { match serde::de::VariantAccess::unit_variant(variant) { - serde::export::Ok(val) => val, - serde::export::Err(err) => { - return serde::export::Err(err); + Ok(val) => val, + Err(err) => { + return Err(err); } }; - serde::export::Ok(io::ErrorKind::UnexpectedEof) + Ok(io::ErrorKind::UnexpectedEof) } } } @@ -1420,8 +1411,8 @@ where "ErrorKind", VARIANTS, Visitor { - marker: serde::export::PhantomData::, - lifetime: serde::export::PhantomData, + marker: marker::PhantomData::, + lifetime: marker::PhantomData, }, ) }