MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / cert_time_to_seconds

Function cert_time_to_seconds

tools/python-3.11.9-amd64/Lib/ssl.py:1490–1518  ·  view source on GitHub ↗

Return the time in seconds since the Epoch, given the timestring representing the "notBefore" or "notAfter" date from a certificate in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale). "notBefore" or "notAfter" dates must use UTC (RFC 5280). Month is one of: Jan Feb Mar

(cert_time)

Source from the content-addressed store, hash-verified

1488# some utility functions
1489
1490def cert_time_to_seconds(cert_time):
1491 """Return the time in seconds since the Epoch, given the timestring
1492 representing the "notBefore" or "notAfter" date from a certificate
1493 in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale).
1494
1495 "notBefore" or "notAfter" dates must use UTC (RFC 5280).
1496
1497 Month is one of: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1498 UTC should be specified as GMT (see ASN1_TIME_print())
1499 """
1500 from time import strptime
1501 from calendar import timegm
1502
1503 months = (
1504 "Jan","Feb","Mar","Apr","May","Jun",
1505 "Jul","Aug","Sep","Oct","Nov","Dec"
1506 )
1507 time_format = ' %d %H:%M:%S %Y GMT' # NOTE: no month, fixed GMT
1508 try:
1509 month_number = months.index(cert_time[:3].title()) + 1
1510 except ValueError:
1511 raise ValueError('time data %r does not match '
1512 'format "%%b%s"' % (cert_time, time_format))
1513 else:
1514 # found valid month
1515 tt = strptime(cert_time[3:], time_format)
1516 # return an integer, the previous mktime()-based implementation
1517 # returned a float (fractional seconds are always zero here).
1518 return timegm((tt[0], month_number) + tt[2:6])
1519
1520PEM_HEADER = "-----BEGIN CERTIFICATE-----"
1521PEM_FOOTER = "-----END CERTIFICATE-----"

Callers

nothing calls this directly

Calls 3

timegmFunction · 0.90
indexMethod · 0.45
titleMethod · 0.45

Tested by

no test coverage detected