From 53db47b447d292b99e97b8d75f419bb6f4638f71 Mon Sep 17 00:00:00 2001 From: Zach Rush Date: Mon, 9 Sep 2019 21:38:58 -0400 Subject: [PATCH] Statement-type definitions will now match the timestamp precision given to them --- stix2/v20/common.py | 10 ++++++++++ stix2/v21/common.py | 9 +-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/stix2/v20/common.py b/stix2/v20/common.py index 0a0cabc..682d4b3 100644 --- a/stix2/v20/common.py +++ b/stix2/v20/common.py @@ -128,6 +128,16 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): self._properties.update([ ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ]) + else: + try: + #statement instances will match the precision given + if kwargs['created'].rfind('.') != -1: + self._properties = copy.deepcopy(self._properties) + self._properties.update([ + ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), + ]) + except AttributeError: + pass if not isinstance(kwargs['definition'], marking_type): defn = _get_dict(kwargs['definition']) diff --git a/stix2/v21/common.py b/stix2/v21/common.py index 13d0ff6..881eced 100644 --- a/stix2/v21/common.py +++ b/stix2/v21/common.py @@ -146,7 +146,7 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type)), ('created_by_ref', ReferenceProperty(type='identity')), - ('created', TimestampProperty(default=lambda: NOW)), + ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), ('external_references', ListProperty(ExternalReference)), ('object_marking_refs', ListProperty(ReferenceProperty(type='marking-definition'))), ('granular_markings', ListProperty(GranularMarking)), @@ -162,13 +162,6 @@ class MarkingDefinition(_STIXBase, _MarkingsMixin): except KeyError: raise ValueError("definition_type must be a valid marking type") - if marking_type == TLPMarking: - # TLP instances in the spec have millisecond precision unlike other markings - self._properties = copy.deepcopy(self._properties) - self._properties.update([ - ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), - ]) - if not isinstance(kwargs['definition'], marking_type): defn = _get_dict(kwargs['definition']) kwargs['definition'] = marking_type(**defn)