/// P: Padding from 1 to 16, |I|C...C|P...P| size must be a multiple of 16
/// |0000000000000000| for error packet (16 bytes length)
/// MMMMMMMMMM: first 10 bytes (most significant) of the HMAC-SHA256 of:
/// P: Padding from 1 to 16, |I|C...C|P...P| size must be a multiple of 16
/// |0000000000000000| for error packet (16 bytes length)
/// MMMMMMMMMM: first 10 bytes (most significant) of the HMAC-SHA256 of:
/// The second argument is the padding length.
pub fn write_with_padding_fun(&self, output: &mut io::Writer, padd_fun: |uint, uint| -> u8) -> WritingResult {
fn packet_data(p: &PacketData) -> Vec<u8> {
/// The second argument is the padding length.
pub fn write_with_padding_fun(&self, output: &mut io::Writer, padd_fun: |uint, uint| -> u8) -> WritingResult {
fn packet_data(p: &PacketData) -> Vec<u8> {
data.reserve_additional(padding_size);
for i in range(0, padding_size) {
data.push(padd_fun(i, padding_size));
data.reserve_additional(padding_size);
for i in range(0, padding_size) {
data.push(padd_fun(i, padding_size));
- let encrypted_data = crypto::encrypt(data.as_slice(), iv_from_timestamp(self.timestamp).as_slice());
-
- println!("data crypted: {}", encrypted_data);
+ let encrypted_data = match crypto::encrypt(data.as_slice(), iv_from_timestamp(self.timestamp).as_slice()) {
+ Some(d) => d,
+ _ => return Err(EncryptError)
+ };
if try_read_io!(input.read(encrypted_data.as_mut_slice_())) != encrypted_data.len() {
return Err(UnconsistentEncryptedSizeError)
}
if try_read_io!(input.read(encrypted_data.as_mut_slice_())) != encrypted_data.len() {
return Err(UnconsistentEncryptedSizeError)
}
- let mut data = crypto::decrypt(encrypted_data.as_slice(), iv_from_timestamp(timestamp).as_slice());
+ let mut data = match crypto::decrypt(encrypted_data.as_slice(), iv_from_timestamp(timestamp).as_slice()) {
+ Some(d) => d,
+ _ => return Err(UnconsistentEncryptedSizeError)
+ };
// Control the size and the content of the padding then remove it.
if packet_type == 0x00 || packet_type == 0xFF {
// Control the size and the content of the padding then remove it.
if packet_type == 0x00 || packet_type == 0xFF {