-
Notifications
You must be signed in to change notification settings - Fork 975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove rustc-serialize (#359) #386
Changes from 4 commits
66193eb
c4a4a86
8537e96
bc9dd63
25f91c0
f8da503
cfb9990
d6b1a3e
7c8f52e
6fb5fd1
2d0f8d6
edf1d69
eb2a9d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
//! Individual messages encoding. | ||
|
||
use bytes::BytesMut; | ||
use crypto::symmetriccipher::SynchronousStreamCipher; | ||
use super::StreamCipher; | ||
use futures::sink::Sink; | ||
use futures::stream::Stream; | ||
use futures::Poll; | ||
|
@@ -36,15 +36,15 @@ use ring::hmac; | |
/// | ||
/// Also implements `Stream` for convenience. | ||
pub struct EncoderMiddleware<S> { | ||
cipher_state: Box<SynchronousStreamCipher>, | ||
cipher_state: Box<StreamCipher>, | ||
hmac_key: hmac::SigningKey, | ||
raw_sink: S, | ||
} | ||
|
||
impl<S> EncoderMiddleware<S> { | ||
pub fn new( | ||
raw_sink: S, | ||
cipher: Box<SynchronousStreamCipher>, | ||
cipher: Box<StreamCipher>, | ||
hmac_key: hmac::SigningKey, | ||
) -> EncoderMiddleware<S> { | ||
EncoderMiddleware { | ||
|
@@ -63,21 +63,15 @@ where | |
type SinkError = S::SinkError; | ||
|
||
fn start_send(&mut self, item: Self::SinkItem) -> StartSend<Self::SinkItem, Self::SinkError> { | ||
let capacity = item.len() + self.hmac_key.digest_algorithm().output_len; | ||
|
||
// Apparently this is the fastest way of doing. | ||
// See https://gist.github.com/kirushik/e0d93759b0cd102f814408595c20a9d0 | ||
let mut out_buffer = BytesMut::from(vec![0; capacity]); | ||
let mut data_buf = item; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this line, instead of renaming the function parameter or using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless (just wanted to keep proto looks but does not need to be here). |
||
// TODO if SinkError gets refactor to SecioError, | ||
// then use try_apply_keystream | ||
self.cipher_state.apply_keystream(&mut data_buf[..]); | ||
let signature = hmac::sign(&self.hmac_key, &data_buf[..]); | ||
data_buf.extend_from_slice(signature.as_ref()); | ||
self.raw_sink.start_send(data_buf) | ||
|
||
{ | ||
let (out_data, out_sign) = out_buffer.split_at_mut(item.len()); | ||
self.cipher_state.process(&item, out_data); | ||
|
||
let signature = hmac::sign(&self.hmac_key, out_data); | ||
out_sign.copy_from_slice(signature.as_ref()); | ||
} | ||
|
||
self.raw_sink.start_send(out_buffer) | ||
} | ||
|
||
#[inline] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cheme is there anything in the git-repo that isn't in the release on crates.io? Or why can't we use that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there was a little change, but RustCrypto guys merge it: RustCrypto/block-ciphers#22 , so we can now use the crates.io dependancy (I change it).