Skip to content

Commit

Permalink
(MINOR) Update xmp_toolkit to v1.7.1, remove Ring dependency, fix b…
Browse files Browse the repository at this point in the history
…uild errors (#407)

* Update `xmp_toolkit` to v1.7.1 to resolve build issue
* Update Wasm to use Crypto::getRandomValues
* Remove dependency on ring
* Removed redundant imports
* Add `truncate(true)` calls to `OpenOptions`
* Update MSRV to 1.73.0
* Pin `id3` to v1.12.0
  • Loading branch information
Dave Kozma authored Feb 23, 2024
1 parent 3dc7bf2 commit adafc0c
Show file tree
Hide file tree
Showing 26 changed files with 112 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
rust_version: [stable, 1.70.0]
rust_version: [stable, 1.73.0]
# exclude:
# - os: windows-latest
# rust_version: stable
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
fail-fast: false
matrix:
target: [aarch64-unknown-linux-gnu]
rust_version: [stable, 1.70.0]
rust_version: [stable, 1.73.0]

steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ We welcome contributions to this project. For information on contributing, prov

## Requirements

The library requires **Rust version 1.70.0** or newer.
The library requires **Rust version 1.73.0** or newer.

### Supported platforms

Expand Down
2 changes: 1 addition & 1 deletion export_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.28.5"
authors = ["Dave Kozma <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2018"
rust-version = "1.70.0"
rust-version = "1.73.0"

[dependencies]
anyhow = "1.0.40"
Expand Down
9 changes: 6 additions & 3 deletions make_test_images/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.28.5"
authors = ["Gavin Peacock <[email protected]>"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.73.0"

[dependencies]
anyhow = "1.0.40"
Expand All @@ -15,8 +15,11 @@ c2pa = { path = "../sdk", features = [
"xmp_write",
] }
env_logger = "0.10"
log = "0.4.8"
image = { version = "0.24.7", default-features = false, features = ["jpeg", "png"] }
log = "0.4.8"
image = { version = "0.24.7", default-features = false, features = [
"jpeg",
"png",
] }
memchr = "2.7.1"
nom = "7.1.3"
regex = "1.5.6"
Expand Down
16 changes: 10 additions & 6 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ readme = "../README.md"
keywords = ["xmp", "metadata"]
categories = ["api-bindings"]
edition = "2021"
rust-version = "1.70.0"
rust-version = "1.73.0"
exclude = ["tests/fixtures"]

[package.metadata.docs.rs]
Expand Down Expand Up @@ -77,7 +77,8 @@ coset = "0.3.1"
extfmt = "0.1.1"
fast-xml = "0.23.1"
hex = "0.4.3"
id3 = "1.7.0"
# Version 1.13.0 doesn't compile under Rust < 1.75, pinning to 1.12.0
id3 = "=1.12.0"
img-parts = "0.3.0"
jfifdump = "0.5.1"
log = "0.4.8"
Expand All @@ -88,11 +89,12 @@ multibase = "0.9.0"
multihash = "0.11.4"
mp4 = "0.13.0"
png_pong = "0.8.2"
rand = "0.8.5"
rand_chacha = "0.3.1"
range-set = "0.0.9"
rasn-ocsp = "0.12.4"
rasn-pkix = "0.12.4"
rasn = "0.12.4"
ring = "0.16.20"
riff = "1.0.1"
schemars = { version = "0.8.13", optional = true }
serde = { version = "1.0.137", features = ["derive"] }
Expand All @@ -112,10 +114,13 @@ x509-certificate = "0.19.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ureq = "2.4.0"
image = { version = "0.24.7", default-features = false, features = ["jpeg", "png"], optional = true }
image = { version = "0.24.7", default-features = false, features = [
"jpeg",
"png",
], optional = true }
instant = "0.1.12"
openssl = { version = "0.10.61", features = ["vendored"], optional = true }
xmp_toolkit = { version = "1.6", optional = true }
xmp_toolkit = { version = "1.7.1", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = { version = "1.0.0", features = ["color"] }
Expand All @@ -124,7 +129,6 @@ getrandom = { version = "0.2.7", features = ["js"] }
# to handle certificate timestamp checking correctly.
instant = { version = "0.1.12", features = ["wasm-bindgen", "inaccurate"] }
js-sys = "0.3.58"
rand = "0.8.5"
rsa = "0.6.1"
serde-wasm-bindgen = "0.5.0"
spki = "0.6.0"
Expand Down
2 changes: 2 additions & 0 deletions sdk/examples/data_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn user_data_hash_with_sdk_hashing() {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&dest)
.unwrap();

Expand Down Expand Up @@ -178,6 +179,7 @@ fn user_data_hash_with_user_hashing() {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&dest)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/assertions/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub mod tests {

use super::*;
use crate::{
assertion::{Assertion, AssertionData},
assertion::AssertionData,
assertions::metadata::{c2pa_source::GENERATOR_REE, DataSource, ReviewRating},
hashed_uri::HashedUri,
};
Expand Down
5 changes: 1 addition & 4 deletions sdk/src/assertions/data_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,7 @@ pub mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::{
assertion::{Assertion, AssertionData},
utils::test::fixture_path,
};
use crate::{assertion::AssertionData, utils::test::fixture_path};

#[test]
fn test_build_assertion() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/assertions/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::assertion::{AssertionCbor, AssertionData};
use crate::assertion::AssertionData;

#[test]
fn assertion_ingredient() {
Expand Down
1 change: 0 additions & 1 deletion sdk/src/assertions/thumbnail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ pub mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::assertions::labels;

// a binary assertion ('deadbeefadbeadbe')
fn some_binary_data() -> Vec<u8> {
Expand Down
1 change: 0 additions & 1 deletion sdk/src/assertions/user_cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pub mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::assertion::Assertion;

const LABEL: &str = "user_test_assertion";
const DATA: &str = r#"{ "l1":"some data", "l2":"some other data" }"#;
Expand Down
1 change: 0 additions & 1 deletion sdk/src/asset_handlers/bmff_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::{
cmp::min,
collections::HashMap,
convert::{From, TryFrom},
fs::{File, OpenOptions},
io::{Read, Seek, SeekFrom, Write},
path::Path,
Expand Down
4 changes: 0 additions & 4 deletions sdk/src/asset_handlers/jpeg_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use std::{
collections::HashMap,
convert::{From, TryFrom},
fs::File,
io::{BufReader, Cursor, Write},
path::*,
Expand Down Expand Up @@ -1036,10 +1035,7 @@ pub mod tests {

use std::io::{Read, Seek};

use img_parts::Bytes;

use super::*;
use crate::asset_io::RemoteRefEmbedType;

#[test]
fn test_extract_xmp() {
Expand Down
1 change: 0 additions & 1 deletion sdk/src/ingredient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ mod tests {
use wasm_bindgen_test::*;

use super::*;
use crate::assertions::Metadata;

#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
Expand Down
1 change: 0 additions & 1 deletion sdk/src/jumbf/boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use std::{
any::Any,
convert::TryInto,
ffi::CString,
fmt,
io::{Read, Result as IoResult, Seek, SeekFrom, Write},
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,7 @@ pub(crate) mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();

Expand Down Expand Up @@ -2353,6 +2354,7 @@ pub(crate) mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/openssl/ec_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::{openssl::temp_signer, utils::test::fixture_path, SigningAlg};
use crate::{openssl::temp_signer, utils::test::fixture_path};

#[test]
fn es256_signer() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/openssl/ec_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn wrap_openssl_err(err: openssl::error::ErrorStack) -> Error {
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::{openssl::temp_signer, utils::test::fixture_path, Signer, SigningAlg};
use crate::{openssl::temp_signer, utils::test::fixture_path, Signer};

#[test]
fn sign_and_validate_es256() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/openssl/ed_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn wrap_openssl_err(err: openssl::error::ErrorStack) -> Error {
mod tests {
#![allow(clippy::unwrap_used)]
use super::*;
use crate::{openssl::temp_signer, utils::test::fixture_path, SigningAlg};
use crate::{openssl::temp_signer, utils::test::fixture_path};

#[test]
fn ed25519_signer() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/openssl/ed_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
#![allow(clippy::unwrap_used)]

use super::*;
use crate::{openssl::temp_signer, utils::test::fixture_path, Signer, SigningAlg};
use crate::{openssl::temp_signer, utils::test::fixture_path, Signer};

#[test]
fn sign_and_validate() {
Expand Down
17 changes: 14 additions & 3 deletions sdk/src/salt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// a funtion to generate a salt value used when hashing
/// data. Providing a unique salt ensures a unique hash for
/// a given data set.
pub trait SaltGenerator {
/// generate a salt vector
fn generate_salt(&self) -> Option<Vec<u8>>;
Expand Down Expand Up @@ -59,13 +60,23 @@ impl SaltGenerator for DefaultSalt {
{
let mut salt = vec![0u8; self.salt_len];
openssl::rand::rand_bytes(&mut salt).ok()?;

Some(salt)
}
#[cfg(all(not(feature = "openssl_sign"), target_arch = "wasm32"))]
{
let salt = crate::wasm::util::get_random_values(self.salt_len).ok()?;

Some(salt)
}
#[cfg(not(feature = "openssl_sign"))]
#[cfg(all(not(feature = "openssl_sign"), not(target_arch = "wasm32")))]
{
use ring::rand::SecureRandom;
use rand::prelude::*;

let mut salt = vec![0u8; self.salt_len];
ring::rand::SystemRandom::new().fill(&mut salt).ok()?;
let mut rng = rand_chacha::ChaCha20Rng::from_entropy();
rng.fill_bytes(&mut salt);

Some(salt)
}
}
Expand Down
14 changes: 8 additions & 6 deletions sdk/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3034,12 +3034,9 @@ pub mod tests {

use super::*;
use crate::{
assertions::{labels::BOX_HASH, Action, Actions, BoxHash, Ingredient, Uuid},
claim::{AssertionStoreJsonFormat, Claim},
jumbf_io::{
get_assetio_handler_from_path, load_jumbf_from_file, save_jumbf_to_file,
update_file_jumbf,
},
assertions::{labels::BOX_HASH, Action, Actions, BoxHash, Uuid},
claim::AssertionStoreJsonFormat,
jumbf_io::{get_assetio_handler_from_path, update_file_jumbf},
status_tracker::*,
utils::{
hash_utils::Hasher,
Expand Down Expand Up @@ -4806,6 +4803,7 @@ pub mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();
output_file.write_all(&out_stream.into_inner()).unwrap();
Expand Down Expand Up @@ -4886,6 +4884,7 @@ pub mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();
output_file.write_all(&out_stream.into_inner()).unwrap();
Expand Down Expand Up @@ -4925,6 +4924,7 @@ pub mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();

Expand Down Expand Up @@ -4987,6 +4987,7 @@ pub mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();

Expand Down Expand Up @@ -5055,6 +5056,7 @@ pub mod tests {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&output)
.unwrap();

Expand Down
8 changes: 3 additions & 5 deletions sdk/src/time_stamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
// specific language governing permissions and limitations under
// each license.

use std::convert::TryFrom;

use async_generic::async_generic;
use bcder::decode::Constructed;
use coset::{sig_structure_data, ProtectedHeader};
Expand Down Expand Up @@ -182,15 +180,15 @@ pub(crate) fn time_stamp_message_http(
message: &[u8],
digest_algorithm: DigestAlgorithm,
) -> Result<Vec<u8>> {
use ring::rand::SecureRandom;
use rand::{thread_rng, Rng};

let mut h = digest_algorithm.digester();
h.update(message);
let digest = h.finish();

let mut random = [0u8; 8];
ring::rand::SystemRandom::new()
.fill(&mut random)
thread_rng()
.try_fill(&mut random)
.map_err(|_| Error::CoseTimeStampGeneration)?;

let request = crate::asn1::rfc3161::TimeStampReq {
Expand Down
Loading

0 comments on commit adafc0c

Please sign in to comment.