From 46fbfb3bc2cb9011ce9952b27e4a187cdd8bf066 Mon Sep 17 00:00:00 2001 From: Santiago Torres Date: Fri, 2 May 2014 19:15:57 -0400 Subject: [PATCH] Fixes wrong schema when adding an expiration that contains microseconds In the case we want a different expiration date on any role, we are adviced to do this: repo.role.expiration = datetime.datetime(some value). In the case we want to use a date somewhere in the future, a normal approach would be to use time deltas: repo.role.expiration = datetime.today() + timedelta(weeks=x) If we use this method we won't be able to set the value since we are most probably producing a datetime object that contains *microseconds*. According to the python specification, the timestamp produced will contain the microseconds value unless it is 0. The simple fix for this issue is to force the microseconds value to be 0 before working with the datetime object. --- tuf/repository_tool.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tuf/repository_tool.py b/tuf/repository_tool.py index b60f7db2..04fa0401 100755 --- a/tuf/repository_tool.py +++ b/tuf/repository_tool.py @@ -1141,6 +1141,10 @@ def expiration(self, datetime_object): message = repr(datetime_object) + ' is not a datetime.datetime() object.' raise tuf.FormatError(message) + # truncate the microseconds value to produce a correct schema string + # of the form yyyy-mm-ddThh:mm:ssZ + datetime_object = datetime_object.replace(microsecond = 0) + # Ensure the expiration has not already passed. current_datetime_object = \ tuf.formats.unix_timestamp_to_datetime(int(time.time()))