aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/crypto/encoding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'lockchain-core/src/crypto/encoding.rs')
-rw-r--r--lockchain-core/src/crypto/encoding.rs24
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