Rm data embedded in images
This commit is contained in:
parent
52382c96a1
commit
08aea30e2b
@ -20,7 +20,6 @@ tsify = { git = "https://github.com/Sosthene00/tsify", branch = "next" }
|
||||
# sdk_common = { path = "../sdk_common" }
|
||||
sdk_common = { git = "https://git.4nkweb.com/4nk/sdk_common.git", branch = "dev" }
|
||||
shamir = { git = "https://github.com/Sosthene00/shamir", branch = "master" }
|
||||
img-parts = "0.3.0"
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3"
|
||||
|
13
src/api.rs
13
src/api.rs
@ -58,7 +58,7 @@ use sdk_common::sp_client::spclient::{
|
||||
use sdk_common::sp_client::spclient::{SpWallet, SpendKey};
|
||||
|
||||
use crate::user::{lock_local_device, set_new_device, Device, LOCAL_DEVICE};
|
||||
use crate::{images, lock_messages, CACHEDMESSAGES};
|
||||
use crate::{lock_messages, CACHEDMESSAGES};
|
||||
|
||||
use crate::process::Process;
|
||||
|
||||
@ -279,17 +279,6 @@ pub fn pair_device(message_id: u32, incoming_pairing_txid: String) -> ApiResult<
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn add_data_to_image(image: Vec<u8>, data: Vec<u8>, is_revoke: bool) -> ApiResult<Vec<u8>> {
|
||||
let mut new_image: Vec<u8>;
|
||||
if is_revoke {
|
||||
new_image = images::BackUpImage::new_revoke(image, &data)?.to_inner();
|
||||
} else {
|
||||
new_image = images::BackUpImage::new_recover(image, &data)?.to_inner();
|
||||
}
|
||||
Ok(new_image)
|
||||
}
|
||||
|
||||
#[derive(Tsify, Serialize, Deserialize)]
|
||||
#[tsify(into_wasm_abi)]
|
||||
#[allow(non_camel_case_types)]
|
||||
|
@ -1,38 +0,0 @@
|
||||
use anyhow::{Error, Result};
|
||||
use img_parts::{jpeg::Jpeg, Bytes, ImageEXIF};
|
||||
use sdk_common::sp_client::bitcoin::secp256k1::SecretKey;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct BackUpImage(Vec<u8>);
|
||||
|
||||
impl BackUpImage {
|
||||
pub fn new_recover(image: Vec<u8>, data: &[u8]) -> Result<Self> {
|
||||
// TODO: sanity check on data
|
||||
let img = write_exif(image, data)?;
|
||||
Ok(Self(img))
|
||||
}
|
||||
|
||||
pub fn new_revoke(image: Vec<u8>, data: &[u8]) -> Result<Self> {
|
||||
// TODO: sanity check on data
|
||||
let img = write_exif(image, data)?;
|
||||
Ok(Self(img))
|
||||
}
|
||||
|
||||
pub fn to_inner(&self) -> Vec<u8> {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
pub fn as_inner(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn write_exif(image: Vec<u8>, data: &[u8]) -> Result<Vec<u8>> {
|
||||
let mut jpeg = Jpeg::from_bytes(Bytes::from(image))?;
|
||||
let data_bytes = Bytes::from(data.to_owned());
|
||||
jpeg.set_exif(Some(data_bytes));
|
||||
let output_image_bytes = jpeg.encoder().bytes();
|
||||
let output_image = output_image_bytes.to_vec();
|
||||
Ok(output_image)
|
||||
}
|
@ -9,7 +9,6 @@ use std::sync::{Mutex, MutexGuard, OnceLock};
|
||||
use tsify::Tsify;
|
||||
|
||||
pub mod api;
|
||||
mod images;
|
||||
mod peers;
|
||||
mod process;
|
||||
mod user;
|
||||
|
Loading…
x
Reference in New Issue
Block a user