Browse code

Fix handling of "now" as a date value.

Xavier G authored on11/05/2020 17:29:07
Showing1 changed files

  • yamltab index 611d14d..1c0c5b2 100755
... ...
@@ -13,7 +13,7 @@ import json
13 13
 import yaml
14 14
 import struct
15 15
 import argparse
16
-from datetime import datetime
16
+from datetime import datetime, timezone
17 17
 from binascii import hexlify, unhexlify
18 18
 
19 19
 # Documents used as reference to implement the keytab format:
... ...
@@ -37,6 +37,7 @@ DEFAULT_PREFIX=BIG_ENDIAN
37 37
 DEFAULT_ENCODING='ascii'
38 38
 VERBOSITY=1
39 39
 CALCSIZE={}
40
+now = None
40 41
 
41 42
 # The following table is based on [3]:
42 43
 NAME_TYPES = {
... ...
@@ -474,6 +475,9 @@ def simple_timestamp_to_full(inentry, index, entry):
474 475
 	elif 'date' in inentry:
475 476
 		entry['date'] = inentry['date']
476 477
 		if inentry['date'] == 'now':
478
+			global now
479
+			if now is None:
480
+				now = int(datetime.now(timezone.utc).timestamp())
477 481
 			entry['timestamp'] = now
478 482
 		else:
479 483
 			try:
... ...
@@ -497,7 +501,6 @@ def simple_enctype_to_full(inentry, index,  entry):
497 501
 	return 2
498 502
 
499 503
 def simple_keytab_to_full(indata):
500
-	now = int(datetime.now().timestamp())
501 504
 	data = {
502 505
 		'version': indata.get('version', 2),
503 506
 		'records': [],