Diff
Not logged in

Differences From Artifact [631b5975fa]:

To Artifact [0a56d01307]:


38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
..
75
76
77
78
79
80
81


82
83
84
85
86
87
88
89
    let n_2_pre_hash = &chunks[n_2].pre_hash;

    let mut pad = [0u8; PAD_SIZE];
    let mut key = [0u8; KEY_SIZE];
    let mut iv = [0u8; IV_SIZE];

    for (pad_iv_el, element) in


        pad.iter_mut().chain(iv.iter_mut()).zip(this_pre_hash.iter().chain(n_2_pre_hash.iter())) {
        *pad_iv_el = *element;
    }

    for (key_el, element) in key.iter_mut().zip(n_1_pre_hash.iter()) {
        *key_el = *element;
    }

................................................................................
    let (pad, key, iv) = pad_key_iv;
    let xor_result = xor(content, &pad);
    let decrypted = encryption::decrypt(&xor_result, &key, &iv)?;
    let mut decompressor = BrotliDecoder::new(vec![]);
    if decompressor.write_all(&decrypted).is_err() {
        return Err(SelfEncryptionError::Compression);
    }


    decompressor.finish().map_err(|_| SelfEncryptionError::Compression)
}

// Helper function to XOR a data with a pad (pad will be rotated to fill the length)
pub fn xor(data: &[u8], &Pad(pad): &Pad) -> Vec<u8> {
    data.iter()
        .zip(pad.iter().cycle())
        .map(|(&a, &b)| a ^ b)







>
>
|







 







>
>
|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    let n_2_pre_hash = &chunks[n_2].pre_hash;

    let mut pad = [0u8; PAD_SIZE];
    let mut key = [0u8; KEY_SIZE];
    let mut iv = [0u8; IV_SIZE];

    for (pad_iv_el, element) in
        pad.iter_mut()
            .chain(iv.iter_mut())
            .zip(this_pre_hash.iter().chain(n_2_pre_hash.iter())) {
        *pad_iv_el = *element;
    }

    for (key_el, element) in key.iter_mut().zip(n_1_pre_hash.iter()) {
        *key_el = *element;
    }

................................................................................
    let (pad, key, iv) = pad_key_iv;
    let xor_result = xor(content, &pad);
    let decrypted = encryption::decrypt(&xor_result, &key, &iv)?;
    let mut decompressor = BrotliDecoder::new(vec![]);
    if decompressor.write_all(&decrypted).is_err() {
        return Err(SelfEncryptionError::Compression);
    }
    decompressor
        .finish()
        .map_err(|_| SelfEncryptionError::Compression)
}

// Helper function to XOR a data with a pad (pad will be rotated to fill the length)
pub fn xor(data: &[u8], &Pad(pad): &Pad) -> Vec<u8> {
    data.iter()
        .zip(pad.iter().cycle())
        .map(|(&a, &b)| a ^ b)