| 192 | } |
| 193 | |
| 194 | pub fn open_raw(&self, nonce: &[u8], encrypted: &[u8]) -> Result<Vec<u8>, Error> { |
| 195 | let encrypted_len = encrypted.len(); |
| 196 | ensure!( |
| 197 | encrypted_len >= crypto_box_curve25519xchacha20poly1305_MACBYTES as usize, |
| 198 | "Unable to decrypt" |
| 199 | ); |
| 200 | let mut decrypted = |
| 201 | vec![0u8; encrypted_len - crypto_box_curve25519xchacha20poly1305_MACBYTES as usize]; |
| 202 | let res = unsafe { |
| 203 | crypto_box_curve25519xchacha20poly1305_open_easy_afternm( |
| 204 | decrypted.as_mut_ptr(), |
| 205 | encrypted.as_ptr(), |
| 206 | encrypted_len as _, |
| 207 | nonce.as_ptr(), |
| 208 | self.0.as_ptr(), |
| 209 | ) |
| 210 | }; |
| 211 | ensure!(res == 0, "Unable to decrypt"); |
| 212 | Ok(decrypted) |
| 213 | } |
| 214 | |
| 215 | pub fn decrypt(&self, nonce: &[u8], encrypted: &[u8]) -> Result<Vec<u8>, Error> { |
| 216 | let encrypted_len = encrypted.len(); |