commit fb1f3fe381e112f62e7254bccbc8120b90b5432e
parent 73574804b62be68e06d8b9c4ceacfba8b08dfca0
Author: mauricefisher64 <92736594+mauricefisher64@users.noreply.github.com>
Date: Wed, 3 Jan 2024 14:27:33 -0500
Remove deprecated twoway crate (#361)
* Fix response strings for BMFF and Box hash statuses
* Add boxhash match to list of success code
* Remove deprecated twoway crate
* Remove twoway exception
* fix make_test_images
Diffstat:
8 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/deny.toml b/deny.toml
@@ -21,7 +21,6 @@ notice = "deny"
ignore = [
"RUSTSEC-2020-0071", # time 0.1.45 (see https://github.com/indygreg/cryptography-rs/issues/10)
"RUSTSEC-2021-0127", # serde_cbor
- "RUSTSEC-2021-0146", # twoway (see https://github.com/contentauth/c2pa-rs/issues/234)
"RUSTSEC-2022-0081", # json (see https://github.com/contentauth/c2pa-rs/issues/318)
"RUSTSEC-2023-0071", # rsa Marvin Attack: (https://jira.corp.adobe.com/browse/CAI-5104)
]
diff --git a/make_test_images/Cargo.toml b/make_test_images/Cargo.toml
@@ -17,8 +17,8 @@ c2pa = { path = "../sdk", features = [
env_logger = "0.10"
log = "0.4.8"
image = { version = "0.24.7", default-features = false, features = ["jpeg", "png"] }
+memchr = "2.7.1"
nom = "7.1.1"
regex = "1.5.6"
serde = "1.0.137"
serde_json = "1.0.81"
-twoway = "0.2.2"
diff --git a/make_test_images/src/make_test_images.rs b/make_test_images/src/make_test_images.rs
@@ -24,9 +24,9 @@ use c2pa::{
create_signer, jumbf_io, Error, Ingredient, IngredientOptions, Manifest, ManifestStore, Signer,
SigningAlg,
};
+use memchr::memmem;
use nom::AsBytes;
use serde::Deserialize;
-use twoway::find_bytes;
const IMAGE_WIDTH: u32 = 2048;
const IMAGE_HEIGHT: u32 = 1365;
@@ -164,7 +164,7 @@ impl MakeTestImages {
fn patch_file(path: &std::path::Path, search_bytes: &[u8], replace_bytes: &[u8]) -> Result<()> {
let mut buf = fs::read(path)?;
- if let Some(splice_start) = find_bytes(&buf, search_bytes) {
+ if let Some(splice_start) = memmem::find(&buf, search_bytes) {
buf.splice(
splice_start..splice_start + search_bytes.len(),
replace_bytes.iter().cloned(),
diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml
@@ -81,6 +81,7 @@ jfifdump = "0.4.0"
log = "0.4.8"
lopdf = { version = "0.31.0", optional = true }
lazy_static = "1.4.0"
+memchr = "2.7.1"
multibase = "0.9.0"
multihash = "0.11.4"
mp4 = "0.13.0"
@@ -99,7 +100,6 @@ sha2 = "0.10.2"
tempfile = "3.1.0"
thiserror = "1.0.40"
treeline = "0.1.0"
-twoway = "0.2.2"
url = "2.2.2"
uuid = { version = "1.3.1", features = ["serde", "v4", "wasm-bindgen"] }
x509-parser = "0.15.0"
diff --git a/sdk/src/asset_handlers/mp3_io.rs b/sdk/src/asset_handlers/mp3_io.rs
@@ -20,8 +20,8 @@ use std::{
use byteorder::{BigEndian, ReadBytesExt};
use conv::ValueFrom;
use id3::{frame::EncapsulatedObject, *};
+use memchr::memmem;
use tempfile::Builder;
-use twoway::find_bytes;
use crate::{
asset_io::{
@@ -108,7 +108,7 @@ fn get_manifest_pos(input_stream: &mut dyn CAIRead) -> Option<(u64, u32)> {
let mut tag_bytes = vec![0u8; header.get_size() as usize];
input_stream.read_exact(tag_bytes.as_mut_slice()).ok()?;
- let pos = find_bytes(&tag_bytes, &manifests[0])?;
+ let pos = memmem::find(&tag_bytes, &manifests[0])?;
return Some((pos as u64, manifests[0].len() as u32));
}
diff --git a/sdk/src/asset_handlers/png_io.rs b/sdk/src/asset_handlers/png_io.rs
@@ -687,7 +687,7 @@ pub mod tests {
use std::io::Write;
- use twoway::find_bytes;
+ use memchr::memmem;
use super::*;
use crate::utils::test;
@@ -717,7 +717,7 @@ pub mod tests {
let positions = get_png_chunk_positions(&mut f).unwrap();
for hop in positions {
- if let Some(start) = find_bytes(&png_bytes, &hop.name) {
+ if let Some(start) = memmem::find(&png_bytes, &hop.name) {
if hop.start != (start - 4) as u64 {
panic!("find_bytes found the wrong position");
// assert!(true);
diff --git a/sdk/src/store.rs b/sdk/src/store.rs
@@ -2997,9 +2997,9 @@ pub mod tests {
use std::io::Write;
+ use memchr::memmem;
use sha2::{Digest, Sha256};
use tempfile::tempdir;
- use twoway::find_bytes;
use super::*;
use crate::{
@@ -3322,7 +3322,7 @@ pub mod tests {
// original data should not be in file anymore check for first 1k
let buf = fs::read(&op).unwrap();
- assert!(find_bytes(&buf, &original_jumbf[0..1024]).is_none());
+ assert!(memmem::find(&buf, &original_jumbf[0..1024]).is_none());
}
#[actix::test]
diff --git a/sdk/src/utils/patch.rs b/sdk/src/utils/patch.rs
@@ -11,7 +11,7 @@
// specific language governing permissions and limitations under
// each license.
-use twoway::find_bytes;
+use memchr::memmem;
use crate::error::{Error, Result};
@@ -23,7 +23,7 @@ returns the location where splice occurred
pub fn patch_bytes(data: &mut Vec<u8>, search_bytes: &[u8], replace_bytes: &[u8]) -> Result<usize> {
// patch data bytes in memory
- if let Some(splice_start) = find_bytes(data, search_bytes) {
+ if let Some(splice_start) = memmem::find(data, search_bytes) {
data.splice(
splice_start..splice_start + search_bytes.len(),
replace_bytes.iter().cloned(),