easy to use conversion from and to string for ethstore::Crypto (#5437)

* easy to use conversion from and to string for ethstore::Crypto

* ethstore uses tempdir instead of devtools

* ethstore does not depend on ethcore-util
This commit is contained in:
Marek Kotewicz
2017-04-11 16:24:56 +08:00
committed by Gav Wood
parent d3b2bcdd79
commit 4f8e61dce9
10 changed files with 82 additions and 47 deletions

View File

@@ -14,10 +14,11 @@
// 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::{fmt, str};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::ser::SerializeStruct;
use serde::de::{Visitor, MapVisitor, Error};
use serde_json;
use super::{Cipher, CipherSer, CipherSerParams, Kdf, KdfSer, KdfSerParams, H256, Bytes};
pub type CipherText = Bytes;
@@ -30,6 +31,20 @@ pub struct Crypto {
pub mac: H256,
}
impl str::FromStr for Crypto {
type Err = serde_json::error::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
serde_json::from_str(s)
}
}
impl From<Crypto> for String {
fn from(c: Crypto) -> Self {
serde_json::to_string(&c).expect("serialization cannot fail, cause all crypto keys are strings")
}
}
enum CryptoField {
Cipher,
CipherParams,