Skip to content

feat: base-serializer runs bomRefDiscrimination on vulnerabilities #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/serialize/baseSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@ SPDX-License-Identifier: Apache-2.0
Copyright (c) OWASP Foundation. All Rights Reserved.
*/

import type { Bom, BomRef, Component } from '../models'
import { treeIteratorSymbol } from '../_helpers/tree'
import type { Bom, BomRef } from '../models'
import { BomRefDiscriminator } from './bomRefDiscriminator'
import type { NormalizerOptions, Serializer, SerializerOptions } from './types'

export abstract class BaseSerializer<NormalizedBom> implements Serializer {
#getAllBomRefs (bom: Bom): Iterable<BomRef> {
const bomRefs = new Set<BomRef>()
function iterComponents (cs: Iterable<Component>): void {
for (const { bomRef, components } of cs) {
bomRefs.add(bomRef)
iterComponents(components)
* #getAllBomRefs (bom: Bom): Generator<BomRef> {
// region from components
if (bom.metadata.component !== undefined) {
yield bom.metadata.component.bomRef
for (const { bomRef } of bom.metadata.component.components[treeIteratorSymbol]()) {
yield bomRef
}
}

if (bom.metadata.component !== undefined) {
bomRefs.add(bom.metadata.component.bomRef)
iterComponents(bom.metadata.component.components)
for (const { bomRef } of bom.components[treeIteratorSymbol]()) {
yield bomRef
}
iterComponents(bom.components)
// endregion from components

return bomRefs.values()
// region from vulnerabilities
for (const { bomRef } of bom.vulnerabilities) {
yield bomRef
}
// endregion from vulnerabilities
}

/**
Expand Down