def asn1_generalizedtime_to_dt(timestamp):
"""Convert ASN.1 GENERALIZEDTIME to datetime.
Useful for deserialization of `OpenSSL.crypto.X509.get_notAfter` and
`OpenSSL.crypto.X509.get_notAfter` outputs.
"""
dt = datetime.datetime.strptime(timestamp[:12], '%Y%m%d%H%M%S')
if timestamp.endswith('Z'):
tzinfo = pytz.utc
else:
sign = -1 if timestamp[-5] == '-' else 1
tzinfo = pytz.FixedOffset(
sign * (int(timestamp[-4:-2]) * 60 + int(timestamp[-2:])))
return tzinfo.localize(dt)
评论列表
文章目录