diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-08-06 16:13:33 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-08-06 16:13:33 +0200 |
commit | 0223592b7eb1a80ff2b7c2ec95e2ad641da07ad8 (patch) | |
tree | 44bcdff914d66d8428584cddfaf6218f163068cf /lockchain-core/src/crypto/encoding.rs | |
parent | 24da2df81265ddfbbeb7dd10fd59eb828afa41b8 (diff) |
More refactoring and trying to get keystores to work properly
Diffstat (limited to 'lockchain-core/src/crypto/encoding.rs')
-rw-r--r-- | lockchain-core/src/crypto/encoding.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lockchain-core/src/crypto/encoding.rs b/lockchain-core/src/crypto/encoding.rs new file mode 100644 index 0000000..0c49490 --- /dev/null +++ b/lockchain-core/src/crypto/encoding.rs @@ -0,0 +1,24 @@ +//! Easy to use encoding utility functions + +use base64; +use std::fmt::Write; + +/// Encode a piece of arbitary data into a bse64 string +pub fn base64_encode(data: &Vec<u8>) -> String { + return base64::encode(data); +} + +/// Decode a base64 string into arbitrary data +pub fn base64_decode(data: &String) -> Vec<u8> { + return base64::decode(data).unwrap(); +} + +/// Simply encode a byte-string as hexadecimal symbols +pub fn encode_hex(data: &str) -> String { + let mut s = String::new(); + for &byte in data.as_bytes() { + write!(&mut s, "{:X}", byte).expect("Unable to HEX encode!"); + } + + return s; +}
\ No newline at end of file |