pub fn edit(
        ciphertext: &[u8],
        key: &[u8],
        nonce: u64,
        offset: usize,
        newtext: &[u8],
    ) -> Result<Vec<u8>, ErrorStack> {
        if offset >= ciphertext.len() {
            return Ok(ciphertext.to_vec());
        }
        let padding = vec![0; offset];
        let input = [padding, newtext.to_vec()].concat();
        // join original ciphertext and edited ciphertext
        let output = [
            ciphertext[0..offset].to_vec(),
            encrypt(&input, key, nonce)?[offset..].to_vec(),
        ]
        .concat();
        Ok(output)
    }
// allows you to "seek" into the ciphertext, decrypt, and re-encrypt with different plaintext
allows you to "seek" into the ciphertext, decrypt, and re-encrypt with different plaintext
allows you to " seek " into the ciphertext decrypt and re - encrypt with different plaintext
pub fn edit(
        ciphertext: &[u8],
        key: &[u8],
        nonce: u64,
        offset: usize,
        newtext: &[u8],
    ) -> Result<Vec<u8>, ErrorStack> {
        if offset >= ciphertext.len() {
            return Ok(ciphertext.to_vec());
        }
        let padding = vec![0; offset];
        let input = [padding, newtext.to_vec()].concat();
        // join original ciphertext and edited ciphertext
        let output = [
            ciphertext[0..offset].to_vec(),
            encrypt(&input, key, nonce)?[offset..].to_vec(),
        ]
        .concat();
        Ok(output)
    }
pub fn edit ( ciphertext : & [ u8 ] , key : & [ u8 ] , nonce : u64 , offset : usize , newtext : & [ u8 ] , ) -> Result < Vec < u8 > , ErrorStack > { if offset >= ciphertext . len ( ) { return Ok ( ciphertext . to_vec ( ) ) ; } let padding = vec ! [ 0 offset ] ; let input = [ padding , newtext . to_vec ( ) ] . concat ( ) ; // join original ciphertext and edited ciphertext let output = [ ciphertext [ 0 .. offset ] . to_vec ( ) , encrypt ( & input , key , nonce ) ? [ offset .. ] . to_vec ( ) , ] . concat ( ) ; Ok ( output ) }
allows you to "seek" into the ciphertext, decrypt, and re-encrypt with different plaintext
allows you to " seek " into the ciphertext decrypt and re - encrypt with different plaintext
ciphertext
&[u8]
key
&[u8]
nonce
u64
offset
usize
newtext
&[u8]