eerimoq / asn1tools

ASN.1 parsing, encoding and decoding.
MIT License
290 stars 98 forks source link

Error Decoding GeneralizedTime #93

Open popitree opened 3 years ago

popitree commented 3 years ago

We have some PER encoded data with timestamp. We are getting error while trying to decode the file.

  1. For sample 20200929110000+0530 we are getting
    Error: Expected a restricted generalized time string, but got '20200929110000+0530'.
    
    ValueError                                Traceback (most recent call last)
    /databricks/python/lib/python3.7/site-packages/asn1tools/codecs/__init__.py in restricted_generalized_time_to_datetime(string)
    295         if string[-1] != 'Z':
    --> 296             raise ValueError
    297 

ValueError:

2. For sample **20200830143000.0Z**

Error: Expected a restricted generalized time string, but got '20200830143000.0Z'.

ValueError Traceback (most recent call last) /databricks/python/lib/python3.7/site-packages/asn1tools/codecs/init.py in restricted_generalized_time_to_datetime(string) 299 if string[-2] == '0': --> 300 raise ValueError 301

ValueError:



In both the cases it is coming from ```restricted_generalized_time_to_datetime(string)``` function.

My understanding both the time formats are valid:
https://www.obj-sys.com/asn1tutorial/node14.html

Also validated from another team that the same data was decoded properly by C++ and Java library.
eerimoq commented 3 years ago

Please add a short script that reproduces the error.