fix: ensure integer bomref discrimination#926
Conversation
The discriminator previously used str(random()) pieces, which could emit scientific notation (e.g. 4.1e-05) and generate invalid BOM ref fragments. Switch to uuid4().int for each segment so we always produce integer-only values while maintaining uniqueness. Add a regression test to lock the BomRef.<int>.<int> format. uuid4() gives ~122 bits of entropy (non-crypto), compared to ~53 bits from random.random(), and the prior decimal-string slicing wasted some of those bits while allowing scientific notation. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
fb05b8c to
b0a9f50
Compare
|
Thanks for the report. I do have some questiosn
invalid to what?
why exactly? I dont see any reason to streamline a thing that has basically no rule nor format. Please explain why you feel this needs changing. |
Some of our validators check I fully agree with you there's no standardized format for Feel free to close this MR if you want to keep things as they are. |
I’ll close this ticket as “Not Planned”, since there’s no existing standard to base further work on.
You really should "relax"(fix!) this validator, since it was build on wrong assumptions, right? |
The discriminator previously used
str(random())pieces, which could emit scientific notation (e.g..756153012152602e-05) and generate invalid BOM ref fragments.uuid4()gives ~122 bits of entropy (non-crypto), compared to ~53 bits fromrandom.random(), and the prior decimal-string slicing wasted some of those bits while allowing scientific notation.Went with
uuid4after exploring in-memory addresses like the JavaScript CycloneDX library and the PHP CycloneDX library which uses a time based approach.A generalized approach for
BomRefemission would be nice I think. Both from a resulting format and generation standpoint. Specifically:uniqidwhich is time based and results in a timestamp in microseconds expressed in hex suffixed by a random digitmath.random()which emits two dot separated 16 digits integer, sometimes in scientific notationInstead of having custom implementations for each library offering support for CycloneDX, they could all rely on unique identifiers such as
uuid4which is natively supported by each language. This would offer strong guarantees of uniqueness along with a common format.