aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml8
-rw-r--r--Android.bp9
-rw-r--r--CHANGELOG.md6
-rw-r--r--Cargo.lock27
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA10
-rw-r--r--README.md2
-rw-r--r--src/common/mod.rs2
-rw-r--r--src/common/tests.rs31
-rw-r--r--src/sign/tests.rs39
-rw-r--r--src/util/tests.rs32
13 files changed, 142 insertions, 30 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 2ca136f..1bc4627 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "46647ee89796d783fa09f0b19b184adda927caba"
+ "sha1": "d375ca3854787ab03ca0fdb7ad0bc489fd7a42a7"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d5ff212..7bec630 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -90,7 +90,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- rust: [1.56.0, 1.57.0]
+ rust: [1.58.0, 1.59.0]
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
@@ -128,7 +128,7 @@ jobs:
with:
toolchain: stable
components: rustfmt, clippy
- - run: cargo +stable clippy --all-features --all-targets
+ - run: cargo +stable clippy --all-features --all-targets -- -Dwarnings
- run: git diff --exit-code
doc:
@@ -171,14 +171,14 @@ jobs:
fetch-depth: 0
- uses: dtolnay/rust-toolchain@a3ac054b2e7d62f514aa1bd57e3508c522fe772d # 1.68.2
with:
- toolchain: nightly-2023-04-01
+ toolchain: nightly-2024-04-01
components: rustfmt
- uses: actions-rs/install@69ec87709ffb5b19a7b5ddbf610cb221498bb1eb # v0.1.2
with:
crate: cargo-tarpaulin
version: 0.25.2
use-tool-cache: true
- - run: cargo +nightly-2023-04-01 tarpaulin --verbose --ignore-tests --all-features --timeout=600 --out Xml
+ - run: cargo +nightly-2024-04-01 tarpaulin --verbose --ignore-tests --all-features --timeout=600 --out Xml
- name: Upload to codecov.io
run: |
bash <(curl -s https://codecov.io/bash)
diff --git a/Android.bp b/Android.bp
index 9fa143c..f9e588c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,5 +1,6 @@
// This file is generated by cargo_embargo.
-// Do not modify this file as changes will be overridden on upgrade.
+// Do not modify this file as most changes will be overridden on upgrade.
+// Content before the first "rust_*" or "genrule" module is preserved.
package {
default_applicable_licenses: ["external_rust_crates_coset_license"],
@@ -23,7 +24,7 @@ rust_test {
host_supported: true,
crate_name: "coset",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.6",
+ cargo_pkg_version: "0.3.7",
srcs: ["src/lib.rs"],
test_suites: ["general-tests"],
auto_gen_config: true,
@@ -47,7 +48,7 @@ rust_library {
host_supported: true,
crate_name: "coset",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.6",
+ cargo_pkg_version: "0.3.7",
srcs: ["src/lib.rs"],
edition: "2018",
features: [
@@ -70,7 +71,7 @@ rust_library_rlib {
name: "libcoset_nostd",
crate_name: "coset",
cargo_env_compat: true,
- cargo_pkg_version: "0.3.6",
+ cargo_pkg_version: "0.3.7",
srcs: ["src/lib.rs"],
edition: "2018",
rustlibs: [
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fe755c..871eacb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
# Change Log
+## 0.3.7 - 2024-04-05
+
+- Bump MSRV to 1.58.
+- Update dependencies.
+- Fix bounds bug for label sorting.
+
## 0.3.6 - 2024-01-15
- Helpers for ordering of fields in a `COSE_Key`:
diff --git a/Cargo.lock b/Cargo.lock
index c7efb02..306da1a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ciborium"
-version = "0.2.1"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926"
+checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e"
dependencies = [
"ciborium-io",
"ciborium-ll",
@@ -15,15 +15,15 @@ dependencies = [
[[package]]
name = "ciborium-io"
-version = "0.2.1"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656"
+checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757"
[[package]]
name = "ciborium-ll"
-version = "0.2.1"
+version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b"
+checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9"
dependencies = [
"ciborium-io",
"half",
@@ -31,7 +31,7 @@ dependencies = [
[[package]]
name = "coset"
-version = "0.3.6"
+version = "0.3.7"
dependencies = [
"ciborium",
"ciborium-io",
@@ -39,10 +39,19 @@ dependencies = [
]
[[package]]
+name = "crunchy"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
+
+[[package]]
name = "half"
-version = "1.8.2"
+version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
+checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0"
+dependencies = [
+ "crunchy",
+]
[[package]]
name = "hex"
diff --git a/Cargo.toml b/Cargo.toml
index 020f39f..6325bc6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2018"
name = "coset"
-version = "0.3.6"
+version = "0.3.7"
authors = [
"David Drysdale <drysdale@google.com>",
"Paul Crowley <paulcrowley@google.com>",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 94529ad..bc68407 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "coset"
-version = "0.3.6"
+version = "0.3.7"
authors = ["David Drysdale <drysdale@google.com>", "Paul Crowley <paulcrowley@google.com>"]
edition = "2018"
license = "Apache-2.0"
diff --git a/METADATA b/METADATA
index 5cbaf3c..680f70f 100644
--- a/METADATA
+++ b/METADATA
@@ -1,5 +1,5 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update rust/crates/coset
+# Usage: tools/external_updater/updater.sh update external/rust/crates/coset
# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "coset"
@@ -8,13 +8,13 @@ third_party {
license_type: NOTICE
last_upgrade_date {
year: 2024
- month: 1
- day: 15
+ month: 4
+ day: 5
}
homepage: "https://crates.io/crates/coset"
identifier {
type: "Archive"
- value: "https://static.crates.io/crates/coset/coset-0.3.6.crate"
- version: "0.3.6"
+ value: "https://static.crates.io/crates/coset/coset-0.3.7.crate"
+ version: "0.3.7"
}
}
diff --git a/README.md b/README.md
index f30ad4e..5fb69b6 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ This crate supports `no_std` (when the `std` feature is not set, which is the de
## Minimum Supported Rust Version
-MSRV is 1.56 (the main `ciborium` dependency is `edition="2021"`)
+MSRV is 1.58.
## Integer Ranges
diff --git a/src/common/mod.rs b/src/common/mod.rs
index 336db50..629b076 100644
--- a/src/common/mod.rs
+++ b/src/common/mod.rs
@@ -216,7 +216,7 @@ impl Ord for Label {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Label::Int(i1), Label::Int(i2)) => match (i1.signum(), i2.signum()) {
- (-1, -1) => (-i1).cmp(&(-i2)),
+ (-1, -1) => i2.cmp(i1),
(-1, 0) => Ordering::Greater,
(-1, 1) => Ordering::Greater,
(0, -1) => Ordering::Less,
diff --git a/src/common/tests.rs b/src/common/tests.rs
index 39ef41c..63cf20c 100644
--- a/src/common/tests.rs
+++ b/src/common/tests.rs
@@ -35,7 +35,7 @@ fn test_error_convert() {
#[test]
fn test_label_encode() {
- let tests = vec![
+ let tests = [
(Label::Int(2), "02"),
(Label::Int(-1), "20"),
(Label::Text("abc".to_owned()), "63616263"),
@@ -68,6 +68,10 @@ fn test_label_sort() {
(Label::Int(0x1234), Label::Int(0x1235)),
(Label::Text("a".to_owned()), Label::Text("ab".to_owned())),
(Label::Text("aa".to_owned()), Label::Text("ab".to_owned())),
+ (Label::Int(i64::MAX - 2), Label::Int(i64::MAX - 1)),
+ (Label::Int(i64::MAX - 1), Label::Int(i64::MAX)),
+ (Label::Int(i64::MIN + 2), Label::Int(i64::MIN + 1)),
+ (Label::Int(i64::MIN + 1), Label::Int(i64::MIN)),
];
for (left, right) in pairs.into_iter() {
let value_cmp = left.cmp(&right);
@@ -182,7 +186,7 @@ fn test_label_decode_fail() {
#[test]
fn test_registered_label_encode() {
- let tests = vec![
+ let tests = [
(RegisteredLabel::Assigned(iana::Algorithm::A192GCM), "02"),
(RegisteredLabel::Assigned(iana::Algorithm::EdDSA), "27"),
(RegisteredLabel::Text("abc".to_owned()), "63616263"),
@@ -276,7 +280,7 @@ impl WithPrivateRange for TestPrivateLabel {
#[test]
fn test_registered_label_with_private_encode() {
- let tests = vec![
+ let tests = [
(
RegisteredLabelWithPrivate::Assigned(TestPrivateLabel::Something),
"01",
@@ -437,3 +441,24 @@ fn test_large_registered_label_with_private_decode_fail() {
expect_err(result, err_msg);
}
}
+
+#[test]
+fn test_as_cbor_value() {
+ let cases = [
+ Value::Null,
+ Value::Bool(true),
+ Value::Bool(false),
+ Value::from(128),
+ Value::from(-1),
+ Value::Bytes(vec![1, 2]),
+ Value::Text("string".to_owned()),
+ Value::Array(vec![Value::from(0)]),
+ Value::Map(vec![]),
+ Value::Tag(1, Box::new(Value::from(0))),
+ Value::Float(1.054571817),
+ ];
+ for val in cases {
+ assert_eq!(val, Value::from_cbor_value(val.clone()).unwrap());
+ assert_eq!(val, val.clone().to_cbor_value().unwrap());
+ }
+}
diff --git a/src/sign/tests.rs b/src/sign/tests.rs
index a35c14c..4fe414f 100644
--- a/src/sign/tests.rs
+++ b/src/sign/tests.rs
@@ -601,6 +601,7 @@ fn test_rfc8152_cose_sign_decode() {
// COSE_Sign structures from RFC 8152 section C.1.
let tests = vec![
(
+ // C.1.1: Single Signature
CoseSignBuilder::new()
.payload(b"This is the content.".to_vec())
.add_signature(
@@ -626,6 +627,7 @@ fn test_rfc8152_cose_sign_decode() {
),
),
(
+ // C.1.2: Multiple Signers
CoseSignBuilder::new()
.payload(b"This is the content.".to_vec())
.add_signature(
@@ -664,6 +666,7 @@ fn test_rfc8152_cose_sign_decode() {
)
),
(
+ // C.1.3: Counter Signature
CoseSignBuilder::new()
.unprotected(HeaderBuilder::new()
.add_counter_signature(
@@ -705,6 +708,7 @@ fn test_rfc8152_cose_sign_decode() {
),
),
(
+ // C.1.4: Signature with Criticality
CoseSignBuilder::new()
.protected(HeaderBuilder::new()
.text_value("reserved".to_owned(), Value::Bool(false))
@@ -1751,3 +1755,38 @@ fn test_sign1_noncanonical() {
.verify_signature(aad, |sig, data| verifier.verify(sig, data))
.is_err());
}
+
+#[test]
+fn test_sig_structure_data() {
+ let protected = ProtectedHeader {
+ original_data: None,
+ header: Header {
+ alg: Some(Algorithm::Assigned(iana::Algorithm::A128GCM)),
+ key_id: vec![1, 2, 3],
+ partial_iv: vec![4, 5, 6],
+ ..Default::default()
+ },
+ };
+ let got = hex::encode(sig_structure_data(
+ SignatureContext::CounterSignature,
+ protected,
+ None,
+ &[0x01, 0x02],
+ &[0x11, 0x12],
+ ));
+ assert_eq!(
+ got,
+ concat!(
+ "84", // 4-arr
+ "70", // 16-tstr
+ "436f756e7465725369676e6174757265", // "CounterSignature"
+ "4d", // 13-bstr for protected
+ "a3", // 3-map
+ "0101", // 1 (alg) => A128GCM
+ "0443010203", // 4 (kid) => 3-bstr
+ "0643040506", // 6 (partial-iv) => 3-bstr
+ "420102", // bstr for aad
+ "421112", // bstr for payload
+ )
+ );
+}
diff --git a/src/util/tests.rs b/src/util/tests.rs
index b75d248..bd1ca98 100644
--- a/src/util/tests.rs
+++ b/src/util/tests.rs
@@ -38,3 +38,35 @@ fn test_cbor_type_error() {
expect_err(e, want);
}
}
+
+#[test]
+#[should_panic]
+fn test_expect_err_but_ok() {
+ let result: Result<i32, crate::CoseError> = Ok(42);
+ expect_err(result, "absent text");
+}
+
+#[test]
+#[should_panic]
+fn test_expect_err_wrong_msg() {
+ let err = cbor_type_error::<()>(&Value::Bool(true), "a");
+ expect_err(err, "incorrect text");
+}
+
+#[test]
+#[should_panic]
+fn test_expect_err_wrong_display_msg() {
+ // Error type where `Debug` shows the message but `Display` doesn't
+ #[allow(dead_code)]
+ #[derive(Debug)]
+ struct Error(&'static str);
+ impl core::fmt::Display for Error {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "other")
+ }
+ }
+
+ let err: Result<i32, Error> = Err(Error("text"));
+ // The expected text appears in the `Debug` output but not the `Display` output.
+ expect_err(err, "text");
+}