Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ All notable changes to this project will be documented in this file.

## unreleased

* Changed
* Enhanced randomness when generating a `serialNumber` (via [#389])
* Build
* Use _TypeScript_ `v4.9.4` now, was `v4.9.3` (via [#366])

[#366]: https://github.com/CycloneDX/cyclonedx-node-npm/pull/366
[#389]: https://github.com/CycloneDX/cyclonedx-node-npm/pull/389

## 1.7.1 - 2022-12-16

Expand Down
15 changes: 12 additions & 3 deletions src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,18 @@ export class BomBuilder {
}

private makeRandomSerialNumber (): string {
const b = [0, 1, 2, 3, 4, 5, 6, 7].map(() => Math.round(Math.random() * 0xFFFF))
b[3] = b[3] & 0x0FFF | 0x4000 // UUID version 4
b[4] = b[4] & 0x3FFF | 0x8000 // UUID version 4 variant 1
const b = [
Math.round(Math.random() * 0xFFFF),
Math.round(Math.random() * 0xFFFF),
Math.round(Math.random() * 0xFFFF),
// UUID version 4
Math.round(Math.random() * 0x0FFF) | 0x4000,
// UUID version 4 variant 1
Math.round(Math.random() * 0x3FFF) | 0x8000,
Math.round(Math.random() * 0xFFFF),
Math.round(Math.random() * 0xFFFF),
Math.round(Math.random() * 0xFFFF)
]
const s = b.map(n => n.toString(16).padStart(4, '0'))
return `urn:uuid:${s[0]}${s[1]}-${s[2]}-${s[3]}-${s[4]}-${s[5]}${s[6]}${s[7]}`
}
Expand Down