This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fixed #2263, geth keys with ciphertext shorter than 32 bytes #2318
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::{ops, str}; | ||
use serde::{Deserialize, Deserializer, Error, Serialize, Serializer}; | ||
use rustc_serialize::hex::{ToHex, FromHex, FromHexError}; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct Bytes(Vec<u8>); | ||
|
||
impl ops::Deref for Bytes { | ||
type Target = [u8]; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl Deserialize for Bytes { | ||
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> | ||
where D: Deserializer | ||
{ | ||
let s = try!(String::deserialize(deserializer)); | ||
let data = try!(s.from_hex().map_err(|e| Error::custom(format!("Invalid hex value {}", e)))); | ||
Ok(Bytes(data)) | ||
} | ||
} | ||
|
||
impl Serialize for Bytes { | ||
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> | ||
where S: Serializer { | ||
serializer.serialize_str(&self.0.to_hex()) | ||
} | ||
} | ||
|
||
impl str::FromStr for Bytes { | ||
type Err = FromHexError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
s.from_hex().map(Bytes) | ||
} | ||
} | ||
|
||
impl From<&'static str> for Bytes { | ||
fn from(s: &'static str) -> Self { | ||
s.parse().unwrap() | ||
} | ||
} | ||
|
||
impl From<Vec<u8>> for Bytes { | ||
fn from(v: Vec<u8>) -> Self { | ||
Bytes(v) | ||
} | ||
} | ||
|
||
impl From<Bytes> for Vec<u8> { | ||
fn from(b: Bytes) -> Self { | ||
b.0 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,7 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use std::fmt; | ||
use std::ops; | ||
use std::str::FromStr; | ||
use std::{ops, fmt, str}; | ||
use rustc_serialize::hex::{FromHex, ToHex}; | ||
use serde::{Serialize, Serializer, Deserialize, Deserializer, Error as SerdeError}; | ||
use serde::de::Visitor; | ||
|
@@ -65,7 +63,7 @@ macro_rules! impl_hash { | |
type Value = $name; | ||
|
||
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: SerdeError { | ||
FromStr::from_str(value).map_err(SerdeError::custom) | ||
value.parse().map_err(SerdeError::custom) | ||
} | ||
|
||
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: SerdeError { | ||
|
@@ -77,7 +75,7 @@ macro_rules! impl_hash { | |
} | ||
} | ||
|
||
impl FromStr for $name { | ||
impl str::FromStr for $name { | ||
type Err = Error; | ||
|
||
fn from_str(value: &str) -> Result<Self, Self::Err> { | ||
|
@@ -92,6 +90,12 @@ macro_rules! impl_hash { | |
} | ||
} | ||
|
||
impl From<&'static str> for $name { | ||
fn from(s: &'static str) -> Self { | ||
s.parse().unwrap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
} | ||
|
||
impl From<[u8; $size]> for $name { | ||
fn from(bytes: [u8; $size]) -> Self { | ||
$name(bytes) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the third definition of this type afaict (
rpc
,json
, and now here) -- is it possible to be more DRY?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They share the same name, but they are not the same.
json::Bytes
deserialization is extremely lenient,rpc::Bytes
deserialization allows0x
prefixes. Here, the format is very strict