diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index 6e916271de79..308c326aac97 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -409,6 +409,48 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { }, }, }, + { + name: "positive-rust-1.50.0-macos", + fixtureDir: "test-fixtures/classifiers/positive/rust-1.50.0", + expected: pkg.Package{ + Name: "rust", + Version: "1.50.0", + Type: "binary", + PURL: "pkg:generic/rust@1.50.0", + Locations: singleLocation("lib/rustlib/aarch64-apple-darwin/lib/libstd-f6f9eec1635e636a.dylib"), + Metadata: pkg.BinaryMetadata{ + Classifier: "rust-standard-library-macos", + }, + }, + }, + { + name: "positive-rust-1.67.1-macos", + fixtureDir: "test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-aarch64-apple-darwin", + expected: pkg.Package{ + Name: "rust", + Version: "1.67.1", + Type: "binary", + PURL: "pkg:generic/rust@1.67.1", + Locations: singleLocation("lib/libstd-16f2b65e77054c42.dylib"), + Metadata: pkg.BinaryMetadata{ + Classifier: "rust-standard-library-macos", + }, + }, + }, + { + name: "positive-rust-1.67.1-linux", + fixtureDir: "test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-x86_64-unknown-linux-musl", + expected: pkg.Package{ + Name: "rust", + Version: "1.67.1", + Type: "binary", + PURL: "pkg:generic/rust@1.67.1", + Locations: singleLocation("lib/libstd-86aefecbddda356d.so"), + Metadata: pkg.BinaryMetadata{ + Classifier: "rust-standard-library-linux", + }, + }, + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index 77e048d9b408..0082dc116685 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -187,4 +187,24 @@ var defaultClassifiers = []classifier{ Package: "postgresql", PURL: mustPURL("pkg:generic/postgresql@version"), }, + { + Class: "rust-standard-library-linux", + FileGlob: "**/libstd-*.so", + EvidenceMatcher: fileContentsVersionMatcher( + // clang LLVM (rustc version 1.48.0 (7eac88abb 2020-11-16)) + `(?m)(\x00)clang LLVM \(rustc version (?P[0-9]+(\.[0-9]+)?(\.[0-9]+)) \(\w+ \d{4}\-\d{2}\-\d{2}\)`), + Package: "rust", + PURL: mustPURL("pkg:generic/rust@version"), + CPEs: singleCPE("cpe:2.3:a:rust-lang:rust:*:*:*:*:*:*:*:*"), + }, + { + Class: "rust-standard-library-macos", + FileGlob: "**/libstd-*.dylib", + EvidenceMatcher: fileContentsVersionMatcher( + // c 1.48.0 (7eac88abb 2020-11-16) + `(?m)c (?P[0-9]+(\.[0-9]+)?(\.[0-9]+)) \(\w+ \d{4}\-\d{2}\-\d{2}\)`), + Package: "rust", + PURL: mustPURL("pkg:generic/rust@version"), + CPEs: singleCPE("cpe:2.3:a:rust-lang:rust:*:*:*:*:*:*:*:*"), + }, } diff --git a/syft/pkg/cataloger/binary/test-fixtures/cache/stereoscope-fixture-image-busybox-d89e839a7c345891baf332e414a51133938a9f5931f5cc698eaf1254bd1226fb.tar b/syft/pkg/cataloger/binary/test-fixtures/cache/stereoscope-fixture-image-busybox-d89e839a7c345891baf332e414a51133938a9f5931f5cc698eaf1254bd1226fb.tar new file mode 100644 index 000000000000..c73a2774a7d8 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/cache/stereoscope-fixture-image-busybox-d89e839a7c345891baf332e414a51133938a9f5931f5cc698eaf1254bd1226fb.tar differ diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.50.0/lib/rustlib/aarch64-apple-darwin/lib/libstd-f6f9eec1635e636a.dylib b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.50.0/lib/rustlib/aarch64-apple-darwin/lib/libstd-f6f9eec1635e636a.dylib new file mode 100644 index 000000000000..8b9c42c6b69a Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.50.0/lib/rustlib/aarch64-apple-darwin/lib/libstd-f6f9eec1635e636a.dylib differ diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-aarch64-apple-darwin/lib/libstd-16f2b65e77054c42.dylib b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-aarch64-apple-darwin/lib/libstd-16f2b65e77054c42.dylib new file mode 100644 index 000000000000..d5949c118f02 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-aarch64-apple-darwin/lib/libstd-16f2b65e77054c42.dylib differ diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-x86_64-unknown-linux-musl/lib/libstd-86aefecbddda356d.so b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-x86_64-unknown-linux-musl/lib/libstd-86aefecbddda356d.so new file mode 100644 index 000000000000..909650227aa3 Binary files /dev/null and b/syft/pkg/cataloger/binary/test-fixtures/classifiers/positive/rust-1.67.1/toolchains/stable-x86_64-unknown-linux-musl/lib/libstd-86aefecbddda356d.so differ