Extern crate crypto: error: source trait is private


#1

Not sure if this is the right place, but there is very little support for the crypto crate: https://github.com/DaGenix/rust-crypto

I tried to decrypt something. The important part is:

let mut out = [0; 4096];
let mut in_buf = buffer::RefReadBuffer::new(&key);
let mut out_buf = buffer::RefWriteBuffer::new(&mut out);
let mut dec = aes::cbc_decryptor(
    aes::KeySize::KeySize128,
    b"cb99b5cbc24db398",
    b"9bc24cb995cb8db3",
    blockmodes::NoPadding);
dec.decrypt(&mut in_buf, &mut out_buf, true);

With this code i get this error:

src/main.rs:98:9: 98:53 error: source trait is private
src/main.rs:98         dec.decrypt(&mut in_buf, &mut out_buf, true);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

I don’t have any clue why.

There is no published doc. I think this are the important parts:

pub fn cbc_decryptor<X: PaddingProcessor + Send + 'static>(key_size: KeySize, key: &[u8], iv: &[u8], padding: X) -> Box<Decryptor + 'static>
pub trait Decryptor {
    fn decrypt(&mut self, input: &mut RefReadBuffer, output: &mut RefWriteBuffer, eof: bool) -> Result<BufferResult, SymmetricCipherError>;
}
impl<T: BlockDecryptor, X: PaddingProcessor> Decryptor for CbcDecryptor<T, X>

Thanks for any help.


#2

That’s a pretty weird error message… You can fix it by saying

use crypto::symmetriccipher::Decryptor;

See also https://github.com/rust-lang/rust/issues/22050


#3

Thanks a lot. Now it works.