Fixed #45, ability to work with old keys and domains.
This commit is contained in:
@@ -545,7 +545,10 @@ impl Chain {
|
|||||||
if let Some(data) = transaction.get_domain_data() {
|
if let Some(data) = transaction.get_domain_data() {
|
||||||
let b = self.get_block(index - 1).unwrap();
|
let b = self.get_block(index - 1).unwrap();
|
||||||
let domain = keystore.decrypt(data.domain.as_slice(), &b.hash.as_slice()[..12]);
|
let domain = keystore.decrypt(data.domain.as_slice(), &b.hash.as_slice()[..12]);
|
||||||
let domain = String::from_utf8(domain.to_vec()).unwrap();
|
let mut domain = String::from_utf8(domain.to_vec()).unwrap();
|
||||||
|
if domain.is_empty() {
|
||||||
|
domain = String::from("unknown");
|
||||||
|
}
|
||||||
trace!("Found my domain {}", domain);
|
trace!("Found my domain {}", domain);
|
||||||
result.insert(domain, (timestamp, data));
|
result.insert(domain, (timestamp, data));
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-4
@@ -2,8 +2,8 @@ use chacha20poly1305::{ChaCha20Poly1305, Key, Nonce};
|
|||||||
use chacha20poly1305::aead::{Aead, NewAead};
|
use chacha20poly1305::aead::{Aead, NewAead};
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
#[allow(unused_imports)]
|
||||||
const FAILURE: &str = "encryption failure!";
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
/// A small wrap-up to use Chacha20 encryption for domain names.
|
/// A small wrap-up to use Chacha20 encryption for domain names.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -20,12 +20,24 @@ impl Chacha {
|
|||||||
|
|
||||||
pub fn encrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
pub fn encrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
||||||
let nonce = Nonce::from_slice(nonce);
|
let nonce = Nonce::from_slice(nonce);
|
||||||
Vec::from(self.cipher.encrypt(nonce, data.as_ref()).expect(FAILURE))
|
match self.cipher.encrypt(nonce, data.as_ref()) {
|
||||||
|
Ok(bytes) => { bytes }
|
||||||
|
Err(_) => {
|
||||||
|
warn!("Error encrypting data!");
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
pub fn decrypt(&self, data: &[u8], nonce: &[u8]) -> Vec<u8> {
|
||||||
let nonce = Nonce::from_slice(nonce);
|
let nonce = Nonce::from_slice(nonce);
|
||||||
Vec::from(self.cipher.decrypt(nonce, data.as_ref()).expect(FAILURE))
|
match self.cipher.decrypt(nonce, data.as_ref()) {
|
||||||
|
Ok(bytes) => { bytes }
|
||||||
|
Err(_) => {
|
||||||
|
warn!("Error decrypting data!");
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user