MCPcopy Index your code
hub / github.com/RustPython/RustPython / cert_time_to_seconds

Function cert_time_to_seconds

Lib/ssl.py:1450–1478  ·  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 Apr Ma

(cert_time)

Source from the content-addressed store, hash-verified

1448# some utility functions
1449
1450def cert_time_to_seconds(cert_time):
1451 """Return the time in seconds since the Epoch, given the timestring
1452 representing the "notBefore" or "notAfter" date from a certificate
1453 in ``"%b %d %H:%M:%S %Y %Z"`` strptime format (C locale).
1454
1455 "notBefore" or "notAfter" dates must use UTC (RFC 5280).
1456
1457 Month is one of: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1458 UTC should be specified as GMT (see ASN1_TIME_print())
1459 """
1460 from time import strptime
1461 from calendar import timegm
1462
1463 months = (
1464 "Jan","Feb","Mar","Apr","May","Jun",
1465 "Jul","Aug","Sep","Oct","Nov","Dec"
1466 )
1467 time_format = ' %d %H:%M:%S %Y GMT' # NOTE: no month, fixed GMT
1468 try:
1469 month_number = months.index(cert_time[:3].title()) + 1
1470 except ValueError:
1471 raise ValueError('time data %r does not match '
1472 'format "%%b%s"' % (cert_time, time_format))
1473 else:
1474 # found valid month
1475 tt = strptime(cert_time[3:], time_format)
1476 # return an integer, the previous mktime()-based implementation
1477 # returned a float (fractional seconds are always zero here).
1478 return timegm((tt[0], month_number) + tt[2:6])
1479
1480PEM_HEADER = "-----BEGIN CERTIFICATE-----"
1481PEM_FOOTER = "-----END CERTIFICATE-----"

Callers

nothing calls this directly

Calls 4

strptimeFunction · 0.90
timegmFunction · 0.90
indexMethod · 0.45
titleMethod · 0.45

Tested by

no test coverage detected