MCPcopy Index your code
hub / github.com/python/cpython / _get_digest_name_and_payload

Function _get_digest_name_and_payload

Lib/multiprocessing/connection.py:887–910  ·  view source on GitHub ↗

Returns a digest name and the payload for a response hash. If a legacy protocol is detected based on the message length or contents the digest name returned will be empty to indicate legacy mode where MD5 and no digest prefix should be sent.

(message)

Source from the content-addressed store, hash-verified

885
886
887def _get_digest_name_and_payload(message): # type: (bytes) -> tuple[str, bytes]
888 """Returns a digest name and the payload for a response hash.
889
890 If a legacy protocol is detected based on the message length
891 or contents the digest name returned will be empty to indicate
892 legacy mode where MD5 and no digest prefix should be sent.
893 """
894 # modern message format: b"{digest}payload" longer than 20 bytes
895 # legacy message format: 16 or 20 byte b"payload"
896 if len(message) in _LEGACY_LENGTHS:
897 # Either this was a legacy server challenge, or we're processing
898 # a reply from a legacy client that sent an unprefixed 16-byte
899 # HMAC-MD5 response. All messages using the modern protocol will
900 # be longer than either of these lengths.
901 return '', message
902 if (message.startswith(b'{') and
903 (curly := message.find(b'}', 1, _MAX_DIGEST_LEN+2)) > 0):
904 digest = message[1:curly]
905 if digest in _ALLOWED_DIGESTS:
906 payload = message[curly+1:]
907 return digest.decode('ascii'), payload
908 raise AuthenticationError(
909 'unsupported message length, missing digest prefix, '
910 f'or unsupported digest: {message=}')
911
912
913def _create_response(authkey, message):

Callers 2

_create_responseFunction · 0.85
_verify_challengeFunction · 0.85

Calls 4

AuthenticationErrorClass · 0.85
startswithMethod · 0.45
findMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…