* ECDKG protocol prototype * added test for enc/dec math * get rid of decryption_session * added licenses * fix after merge * get rid of unused serde dependency * doc * decryption session [without commutative enc] * failed_dec_session * fixed tests * added commen * added more decryption session tests * helper to localize an issue * more computations to localize error * decryption_session::SessionParams * added tests for EC math to localize problem * secretstore network transport * encryption_session_works_over_network * network errors processing * connecting to KeyServer * licenses * get rid of debug println-s * fixed secretstore args * encryption results are stored in KS database * decryption protocol works over network * enc/dec Session traits * fixing warnings * fix after merge * on-chain ACL checker proto * fixed compilation * fixed compilation * finally fixed <odd>-of-N-scheme * temporary commented test * 1-of-N works in math * scheme 1-of-N works * updated AclStorage with real contract ABI * remove unnecessary unsafety * fixed grumbles * wakeup on access denied * encrypt secretstore messages * 'shadow' decryption * fix grumbles * lost files * secretstore cli-options * decryption seccion when ACL check failed on master * disallow regenerating key for existing document * removed obsolete TODO * fix after merge * switched to tokio_io * fix after merge * fix after merge * fix after merge * fix after merge * fix after merge * fixed test * fix after merge
72 lines
2.2 KiB
Rust
72 lines
2.2 KiB
Rust
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
|
// This file is part of Parity.
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// 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::io;
|
|
use futures::{Future, Poll};
|
|
use tokio_io::AsyncWrite;
|
|
use tokio_io::io::{WriteAll, write_all};
|
|
use ethkey::KeyPair;
|
|
use key_server_cluster::message::Message;
|
|
use key_server_cluster::io::{serialize_message, encrypt_message};
|
|
|
|
/// Write plain message to the channel.
|
|
pub fn write_message<A>(a: A, message: Message) -> WriteMessage<A> where A: AsyncWrite {
|
|
let (error, future) = match serialize_message(message)
|
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string())) {
|
|
Ok(message) => (None, write_all(a, message.into())),
|
|
Err(error) => (Some(error), write_all(a, Vec::new())),
|
|
};
|
|
WriteMessage {
|
|
error: error,
|
|
future: future,
|
|
}
|
|
}
|
|
|
|
/// Write encrypted message to the channel.
|
|
pub fn write_encrypted_message<A>(a: A, key: &KeyPair, message: Message) -> WriteMessage<A> where A: AsyncWrite {
|
|
let (error, future) = match serialize_message(message)
|
|
.and_then(|message| encrypt_message(key, message))
|
|
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string())) {
|
|
Ok(message) => (None, write_all(a, message.into())),
|
|
Err(error) => (Some(error), write_all(a, Vec::new())),
|
|
};
|
|
|
|
|
|
WriteMessage {
|
|
error: error,
|
|
future: future,
|
|
}
|
|
}
|
|
|
|
/// Future message write.
|
|
pub struct WriteMessage<A> {
|
|
error: Option<io::Error>,
|
|
future: WriteAll<A, Vec<u8>>,
|
|
}
|
|
|
|
impl<A> Future for WriteMessage<A> where A: AsyncWrite {
|
|
type Item = (A, Vec<u8>);
|
|
type Error = io::Error;
|
|
|
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
|
if let Some(err) = self.error.take() {
|
|
return Err(err);
|
|
}
|
|
|
|
self.future.poll()
|
|
}
|
|
}
|