Skip to content

Commit 1a453d3

Browse files
authored
Merge pull request #217 from rust-secure-code/format-revision
Add format revision
2 parents 3496266 + 34c5440 commit 1a453d3

File tree

13 files changed

+169
-116
lines changed

13 files changed

+169
-116
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

auditable-cyclonedx/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auditable-cyclonedx"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Sergey \"Shnatsel\" Davidoff <shnatsel@gmail.com>"]
66
license = "MIT OR Apache-2.0"
@@ -12,4 +12,4 @@ categories = ["encoding"]
1212

1313
[dependencies]
1414
cyclonedx-bom = "0.8.0"
15-
auditable-serde = {version = "0.8.0", path = "../auditable-serde"}
15+
auditable-serde = {version = "0.9.0", path = "../auditable-serde"}

auditable-info/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auditable-info"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
authors = ["Sergey \"Shnatsel\" Davidoff <shnatsel@gmail.com>"]
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/rust-secure-code/cargo-auditable"
@@ -13,7 +13,7 @@ edition = "2018"
1313
[dependencies]
1414
auditable-extract = {version = "0.3.4", path = "../auditable-extract", default-features = false }
1515
miniz_oxide = { version = "0.8.0", features = ["std"] }
16-
auditable-serde = {version = "0.8.0", path = "../auditable-serde", optional = true}
16+
auditable-serde = {version = "0.9.0", path = "../auditable-serde", optional = true}
1717
serde_json = { version = "1.0.57", optional = true }
1818

1919
[features]

auditable-serde/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auditable-serde"
3-
version = "0.8.0"
3+
version = "0.9.0"
44
authors = ["Sergey \"Shnatsel\" Davidoff <shnatsel@gmail.com>"]
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/rust-secure-code/cargo-auditable"

auditable-serde/src/lib.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,41 @@ use std::str::FromStr;
3636
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
3737
pub struct VersionInfo {
3838
pub packages: Vec<Package>,
39+
/// Format revision. Identifies the data source for the audit data.
40+
///
41+
/// Format revisions are **backwards compatible.**
42+
/// If an unknown format is encountered, it should be treated as the highest known preceding format.
43+
/// For example, if formats `0`, `1` and `8` are known, format `4` should be treated as if it's `1`.
44+
///
45+
/// # Known formats
46+
///
47+
/// ## 0 (or the field is absent)
48+
///
49+
/// Generated based on the data provided by [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html).
50+
///
51+
/// There are multiple [known](https://github.com/rust-lang/cargo/issues/7754)
52+
/// [issues](https://github.com/rust-lang/cargo/issues/10718) with this data source,
53+
/// leading to the audit data sometimes including more dependencies than are really used in the build.
54+
///
55+
/// However, is the only machine-readable data source available on stable Rust as of v1.88.
56+
///
57+
/// Additionally, this format incorrectly includes [procedural macros](https://doc.rust-lang.org/reference/procedural-macros.html)
58+
/// and their dependencies as runtime dependencies while in reality they are build-time dependencies.
59+
///
60+
/// ## 1
61+
///
62+
/// Same as 0, but correctly records proc-macros and their dependencies as build-time dependencies.
63+
///
64+
/// May still include slightly more dependencies than are actually used, especially in workspaces.
65+
///
66+
/// ## 8
67+
///
68+
/// Generated using Cargo's [SBOM precursor](https://doc.rust-lang.org/cargo/reference/unstable.html#sbom) as the data source.
69+
///
70+
/// This data is highly accurate, but as of Rust v1.88 can only be generated using a nightly build of Cargo.
71+
#[serde(default)]
72+
#[serde(skip_serializing_if = "is_default")]
73+
pub format: u32,
3974
}
4075

4176
/// A single package in the dependency tree
@@ -117,7 +152,7 @@ pub enum DependencyKind {
117152
Runtime,
118153
}
119154

120-
fn is_default<T: Default + PartialEq>(value: &T) -> bool {
155+
pub(crate) fn is_default<T: Default + PartialEq>(value: &T) -> bool {
121156
let default_value = T::default();
122157
value == &default_value
123158
}

auditable-serde/src/validation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
use crate::{Package, VersionInfo};
1+
use crate::{is_default, Package, VersionInfo};
22
use serde::{Deserialize, Serialize};
33
use std::{convert::TryFrom, fmt::Display};
44

55
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
6-
pub struct RawVersionInfo {
6+
pub(crate) struct RawVersionInfo {
77
pub packages: Vec<Package>,
8+
#[serde(default)]
9+
#[serde(skip_serializing_if = "is_default")]
10+
pub format: u32,
811
}
912

1013
pub enum ValidationError {
@@ -36,6 +39,7 @@ impl TryFrom<RawVersionInfo> for VersionInfo {
3639
} else {
3740
Ok(VersionInfo {
3841
packages: v.packages,
42+
format: v.format,
3943
})
4044
}
4145
}
@@ -99,6 +103,7 @@ mod tests {
99103
let pkg1 = dummy_package(1, false, vec![0]);
100104
let raw = RawVersionInfo {
101105
packages: vec![pkg0, pkg1],
106+
format: 0,
102107
};
103108
assert!(VersionInfo::try_from(raw).is_err());
104109
}
@@ -109,6 +114,7 @@ mod tests {
109114
let pkg1 = dummy_package(1, false, vec![]);
110115
let raw = RawVersionInfo {
111116
packages: vec![pkg0, pkg1],
117+
format: 0,
112118
};
113119
assert!(VersionInfo::try_from(raw).is_ok());
114120
}

auditable2cdx/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "auditable2cdx"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
authors = ["Sergey \"Shnatsel\" Davidoff <shnatsel@gmail.com>"]
66
license = "MIT OR Apache-2.0"
@@ -10,8 +10,8 @@ description = "Command-line tool to recover `cargo auditable` data in CycloneDX
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[dependencies]
13-
auditable-info = {version = "0.9.0", path = "../auditable-info"}
14-
auditable-cyclonedx = {version = "0.1.0", path = "../auditable-cyclonedx"}
13+
auditable-info = {version = "0.10.0", path = "../auditable-info"}
14+
auditable-cyclonedx = {version = "0.2.0", path = "../auditable-cyclonedx"}
1515
serde_json = {version = "1.0.114", features = ["preserve_order"] } # the feature is needed for workarounds module only
1616

1717
[package.metadata.dist]

cargo-auditable.schema.json

Lines changed: 99 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,107 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"$id": "https://rustsec.org/schemas/cargo-auditable.json",
4-
"title": "cargo-auditable schema",
5-
"description": "Describes the `VersionInfo` JSON data structure that cargo-auditable embeds into Rust binaries.",
6-
"type": "object",
7-
"required": [
8-
"packages"
9-
],
10-
"properties": {
11-
"packages": {
12-
"type": "array",
13-
"items": {
14-
"$ref": "#/definitions/Package"
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://rustsec.org/schemas/cargo-auditable.json",
4+
"title": "cargo-auditable schema",
5+
"description": "Describes the `VersionInfo` JSON data structure that cargo-auditable embeds into Rust binaries.",
6+
"type": "object",
7+
"required": [
8+
"packages"
9+
],
10+
"properties": {
11+
"format": {
12+
"description": "Format revision. Identifies the data source for the audit data.\n\nFormat revisions are **backwards compatible.** If an unknown format is encountered, it should be treated as the highest known preceding format. For example, if formats `0`, `1` and `8` are known, format `4` should be treated as if it's `1`.\n\n# Known formats\n\n## 0 (or the field is absent)\n\nGenerated based on the data provided by [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html).\n\nThere are multiple [known](https://github.com/rust-lang/cargo/issues/7754) [issues](https://github.com/rust-lang/cargo/issues/10718) with this data source, leading to the audit data sometimes including more dependencies than are really used in the build.\n\nHowever, is the only machine-readable data source available on stable Rust as of v1.88.\n\nAdditionally, this format incorrectly includes [procedural macros](https://doc.rust-lang.org/reference/procedural-macros.html) and their dependencies as runtime dependencies while in reality they are build-time dependencies.\n\n## 1\n\nSame as 0, but correctly records proc-macros and their dependencies as build-time dependencies.\n\nMay still include slightly more dependencies than are actually used, especially in workspaces.\n\n## 8\n\nGenerated using Cargo's [SBOM precursor](https://doc.rust-lang.org/cargo/reference/unstable.html#sbom) as the data source.\n\nThis data is highly accurate, but as of Rust v1.88 can only be generated using a nightly build of Cargo.",
13+
"type": "integer",
14+
"format": "uint32",
15+
"minimum": 0.0
16+
},
17+
"packages": {
18+
"type": "array",
19+
"items": {
20+
"$ref": "#/definitions/Package"
21+
}
22+
}
23+
},
24+
"definitions": {
25+
"DependencyKind": {
26+
"type": "string",
27+
"enum": [
28+
"build",
29+
"runtime"
30+
]
31+
},
32+
"Package": {
33+
"description": "A single package in the dependency tree",
34+
"type": "object",
35+
"required": [
36+
"name",
37+
"source",
38+
"version"
39+
],
40+
"properties": {
41+
"dependencies": {
42+
"description": "Packages are stored in an ordered array both in the `VersionInfo` struct and in JSON. Here we refer to each package by its index in the array. May be omitted if the list is empty.",
43+
"type": "array",
44+
"items": {
45+
"type": "integer",
46+
"format": "uint",
47+
"minimum": 0.0
48+
}
49+
},
50+
"kind": {
51+
"description": "\"build\" or \"runtime\". May be omitted if set to \"runtime\". If it's both a build and a runtime dependency, \"runtime\" is recorded.",
52+
"allOf": [
53+
{
54+
"$ref": "#/definitions/DependencyKind"
55+
}
56+
]
57+
},
58+
"name": {
59+
"description": "Crate name specified in the `name` field in Cargo.toml file. Examples: \"libc\", \"rand\"",
60+
"type": "string"
61+
},
62+
"root": {
63+
"description": "Whether this is the root package in the dependency tree. There should only be one root package. May be omitted if set to `false`.",
64+
"type": "boolean"
65+
},
66+
"source": {
67+
"description": "Currently \"git\", \"local\", \"crates.io\" or \"registry\". Designed to be extensible with other revision control systems, etc.",
68+
"allOf": [
69+
{
70+
"$ref": "#/definitions/Source"
1571
}
72+
]
73+
},
74+
"version": {
75+
"description": "The package's version in the [semantic version](https://semver.org) format.",
76+
"type": "string"
1677
}
78+
}
1779
},
18-
"definitions": {
19-
"DependencyKind": {
20-
"type": "string",
21-
"enum": [
22-
"build",
23-
"runtime"
24-
]
80+
"Source": {
81+
"description": "Serializes to \"git\", \"local\", \"crates.io\" or \"registry\". Designed to be extensible with other revision control systems, etc.",
82+
"oneOf": [
83+
{
84+
"type": "string",
85+
"enum": [
86+
"CratesIo",
87+
"Git",
88+
"Local",
89+
"Registry"
90+
]
2591
},
26-
"Package": {
27-
"description": "A single package in the dependency tree",
28-
"type": "object",
29-
"required": [
30-
"name",
31-
"source",
32-
"version"
33-
],
34-
"properties": {
35-
"dependencies": {
36-
"description": "Packages are stored in an ordered array both in the `VersionInfo` struct and in JSON. Here we refer to each package by its index in the array. May be omitted if the list is empty.",
37-
"type": "array",
38-
"items": {
39-
"type": "integer",
40-
"format": "uint",
41-
"minimum": 0.0
42-
}
43-
},
44-
"kind": {
45-
"description": "\"build\" or \"runtime\". May be omitted if set to \"runtime\". If it's both a build and a runtime dependency, \"runtime\" is recorded.",
46-
"allOf": [
47-
{
48-
"$ref": "#/definitions/DependencyKind"
49-
}
50-
]
51-
},
52-
"name": {
53-
"description": "Crate name specified in the `name` field in Cargo.toml file. Examples: \"libc\", \"rand\"",
54-
"type": "string"
55-
},
56-
"root": {
57-
"description": "Whether this is the root package in the dependency tree. There should only be one root package. May be omitted if set to `false`.",
58-
"type": "boolean"
59-
},
60-
"source": {
61-
"description": "Currently \"git\", \"local\", \"crates.io\" or \"registry\". Designed to be extensible with other revision control systems, etc.",
62-
"allOf": [
63-
{
64-
"$ref": "#/definitions/Source"
65-
}
66-
]
67-
},
68-
"version": {
69-
"description": "The package's version in the [semantic version](https://semver.org) format.",
70-
"type": "string"
71-
}
92+
{
93+
"type": "object",
94+
"required": [
95+
"Other"
96+
],
97+
"properties": {
98+
"Other": {
99+
"type": "string"
72100
}
73-
},
74-
"Source": {
75-
"description": "Serializes to \"git\", \"local\", \"crates.io\" or \"registry\". Designed to be extensible with other revision control systems, etc.",
76-
"oneOf": [
77-
{
78-
"type": "string",
79-
"enum": [
80-
"CratesIo",
81-
"Git",
82-
"Local",
83-
"Registry"
84-
]
85-
},
86-
{
87-
"type": "object",
88-
"required": [
89-
"Other"
90-
],
91-
"properties": {
92-
"Other": {
93-
"type": "string"
94-
}
95-
},
96-
"additionalProperties": false
97-
}
98-
]
101+
},
102+
"additionalProperties": false
99103
}
104+
]
100105
}
101-
}
106+
}
107+
}

0 commit comments

Comments
 (0)