commit 45d666e0d023721257fb07df56e9e9f29d46e782
parent 362880eac85af52a734508f563fe97cbb5c7200d
Author: Gavin Peacock <gpeacock@adobe.com>
Date: Wed, 21 Jun 2023 13:24:21 -0700
Updates (#270)
* base64 update
* rust 2021 edition
* serde_wasm_bindgen update
* update min wasm-bindgen version
Diffstat:
9 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/make_test_images/Cargo.toml b/make_test_images/Cargo.toml
@@ -3,7 +3,7 @@ name = "make_test_images"
version = "0.23.2"
authors = ["Gavin Peacock <gpeacock@adobe.com>"]
license = "MIT OR Apache-2.0"
-edition = "2018"
+edition = "2021"
rust-version = "1.65.0"
[dependencies]
diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml
@@ -16,7 +16,7 @@ repository = "https://github.com/contentauth/c2pa-rs"
readme = "../README.md"
keywords = ["xmp", "metadata"]
categories = ["api-bindings"]
-edition = "2018"
+edition = "2021"
rust-version = "1.65.0"
exclude = ["tests/fixtures"]
@@ -58,7 +58,7 @@ crate-type = ["lib"]
asn1-rs = "0.5.2"
async-trait = { version = "0.1.48" }
atree = "0.5.2"
-base64 = "0.13.0"
+base64 = "0.21.2"
bcder = "0.7.1"
blake3 = "1.0.0"
bytes = "1.4.0"
@@ -117,9 +117,9 @@ 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.4.3"
+serde-wasm-bindgen = "0.5.0"
spki = "0.6.0"
-wasm-bindgen = "0.2.81"
+wasm-bindgen = "0.2.83"
wasm-bindgen-futures = "0.4.31"
web-sys = { version = "0.3.58", features = [
"Crypto",
diff --git a/sdk/src/asset_handlers/svg_io.rs b/sdk/src/asset_handlers/svg_io.rs
@@ -38,6 +38,7 @@ use crate::{
RemoteRefEmbed,
},
error::{Error, Result},
+ utils::base64,
};
static SUPPORTED_TYPES: [&str; 7] = [
@@ -245,7 +246,8 @@ fn detect_manifest_location(
Error::InvalidAsset("XML manifest tag invalid content".to_string())
})?;
- output = Some(base64::decode(s.into_bytes()).map_err(|_e| {
+ output = Some(base64::decode(&s).map_err(|_e| {
+ dbg!(_e);
Error::InvalidAsset("XML bad base64 encoding".to_string())
})?);
}
@@ -455,7 +457,7 @@ impl CAIWriter for SvgIO {
detect_manifest_location(&mut output_stream)?;
let decoded_manifest = decoded_manifest_opt.ok_or(Error::JumbfNotFound)?;
- let encoded_manifest_len = base64::encode(decoded_manifest).len();
+ let encoded_manifest_len = base64::encode(&decoded_manifest).len();
positions.push(HashObjectPositions {
offset: manifest_pos,
@@ -572,7 +574,7 @@ impl AssetPatch for SvgIO {
if let Some(manifest_bytes) = asset_manifest_opt {
// base 64 encode
- let encoded_manifest_bytes = base64::encode(manifest_bytes);
+ let encoded_manifest_bytes = base64::encode(&manifest_bytes);
// can patch if encoded lengths are ==
if encoded_store_bytes.len() == encoded_manifest_bytes.len() {
input_file.seek(SeekFrom::Start(insertion_point as u64))?;
@@ -747,8 +749,8 @@ pub mod tests {
let mut manifests_buf: Vec<u8> = vec![0u8; op.length];
of.seek(SeekFrom::Start(op.offset as u64)).unwrap();
of.read_exact(manifests_buf.as_mut_slice()).unwrap();
-
- let decoded_data = base64::decode(&manifests_buf).unwrap();
+ let buf_str = std::str::from_utf8(&manifests_buf).unwrap();
+ let decoded_data = base64::decode(buf_str).unwrap();
if vec_compare(more_data, &decoded_data) {
success = true;
}
diff --git a/sdk/src/claim.rs b/sdk/src/claim.rs
@@ -45,7 +45,10 @@ use crate::{
jumbf_io::{get_assetio_handler, get_assetio_handler_from_path},
salt::{DefaultSalt, SaltGenerator, NO_SALT},
status_tracker::{log_item, OneShotStatusTracker, StatusTracker},
- utils::hash_utils::{hash_by_alg, vec_compare, verify_by_alg},
+ utils::{
+ base64,
+ hash_utils::{hash_by_alg, vec_compare, verify_by_alg},
+ },
validation_status,
validator::ValidationInfo,
ClaimGeneratorInfo,
diff --git a/sdk/src/manifest_store.rs b/sdk/src/manifest_store.rs
@@ -23,6 +23,7 @@ use crate::{
claim::ClaimAssetData,
status_tracker::{DetailedStatusTracker, StatusTracker},
store::Store,
+ utils::base64,
validation_status::{status_for_store, ValidationStatus},
Manifest, Result,
};
@@ -322,7 +323,7 @@ impl std::fmt::Display for ManifestStore {
"{}\"{}\": \"{}\"{}",
&json[..index],
tag,
- base64::encode(bytes),
+ base64::encode(&bytes),
&json[index + idx2 + 1..]
);
}
diff --git a/sdk/src/manifest_store_report.rs b/sdk/src/manifest_store_report.rs
@@ -25,6 +25,7 @@ use crate::{
claim::Claim,
status_tracker::{DetailedStatusTracker, StatusTracker},
store::Store,
+ utils::base64,
validation_status::ValidationStatus,
Result,
};
@@ -363,7 +364,7 @@ fn b64_tag(mut json: String, tag: &str) -> String {
"{}\"{}\": \"{}\"{}",
&json[..index],
tag,
- base64::encode(bytes),
+ base64::encode(&bytes),
&json[index + idx2 + 1..]
);
}
diff --git a/sdk/src/ocsp_utils.rs b/sdk/src/ocsp_utils.rs
@@ -21,6 +21,7 @@ use crate::{
error::{Error, Result},
openssl::check_chain_order_der,
status_tracker::{log_item, StatusTracker},
+ utils::base64,
validation_status,
};
@@ -91,7 +92,7 @@ pub fn get_ocsp_response(certs: &[Vec<u8>]) -> Option<OcspData> {
let mut ocsp_req = ocsp::OcspRequest::new().ok()?;
ocsp_req.add_id(cert_id).ok()?;
- let request_str = base64::encode(ocsp_req.to_der().ok()?);
+ let request_str = base64::encode(&ocsp_req.to_der().ok()?);
let req_url = url.join(&request_str).ok()?;
diff --git a/sdk/src/utils/base64.rs b/sdk/src/utils/base64.rs
@@ -0,0 +1,22 @@
+// Copyright 2022 Adobe. All rights reserved.
+// This file is licensed to you under the Apache License,
+// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
+// or the MIT license (http://opensource.org/licenses/MIT),
+// at your option.
+
+// Unless required by applicable law or agreed to in writing,
+// this software is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
+// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
+// specific language governing permissions and limitations under
+// each license.
+
+use base64::{engine::general_purpose, Engine as _};
+
+pub(crate) fn encode(data: &[u8]) -> String {
+ general_purpose::STANDARD.encode(data)
+}
+
+pub(crate) fn decode(data: &str) -> Result<Vec<u8>, base64::DecodeError> {
+ general_purpose::STANDARD.decode(data)
+}
diff --git a/sdk/src/utils/mod.rs b/sdk/src/utils/mod.rs
@@ -11,6 +11,7 @@
// specific language governing permissions and limitations under
// each license.
+pub(crate) mod base64;
pub(crate) mod cbor_types;
#[allow(dead_code)]
pub(crate) mod hash_utils;