-
Notifications
You must be signed in to change notification settings - Fork 120
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
Fix deterministic ids #402
Conversation
Codecov Report
@@ Coverage Diff @@
## master #402 +/- ##
==========================================
+ Coverage 98.43% 98.44% +0.01%
==========================================
Files 127 128 +1
Lines 14652 14694 +42
==========================================
+ Hits 14423 14466 +43
+ Misses 229 228 -1
Continue to review full report at Codecov.
|
Can you see any issues with using refs as contributing properties? There are a few objects that use refs. I know I have to be careful about the order in which I create the ids when creating the deterministic ids by hand, but maybe it would never be an issue using python-stix2. |
By hand, I guess you'd have to create the referent object IDs first, then you can populate the ref properties with those IDs and then canonicalize. It is similar with the stix2 library: you need some value to use for the ref property, so you have to create the referent object (or its ID) first. Circular references are impossible if both SCOs require UUIDv5's. You'd have to switch one to a v4 to make that work. |
one which had been obsoleted by a newer one.
described it and gave the RFC number...
given. Now, an exception is raised. Added a unit test for this.
test suite to the test suite specific to testing deterministic IDs. This keeps the tests for that specific system in one place.
4d44d26
to
5a5484d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @chisholm!
Fixes #395, #396 .
Revamped deterministic ID generation code:
"Primary" object initialization is now done first, and the resulting property values are what are used to create the deterministic ID instead of whatever kwargs had been passed into the constructor.
Conversion to a JSON-serializable object (as preparation for canonicalization) should now handle all types of property values.
The way this conversion should be done isn't clear from the spec. E.g. it says to use the "list of ID Contributing Properties" and create canonical JSON from that, but (a) not all property values are compatible with JSON, and (b) it doesn't describe what from each property to use (name+value or just value?). For (a), property values which are incompatible with JSON are first serialized according to the JSON serialization rules for the type. This produces a string, which is JSON compatible and so can be canonicalized. This notably applies to timestamps, for which the library uses instances of a datetime subclass for convenience, which will get their spec-prescribed textual format. For (b), the decision is that both names and values are important, so we create a canonical JSON object, rather than taking the word "list" as given in the spec, literally.