Skip to content

Raise TypeError in pure Python hmac.digest for non-bytes keys #155426

Open

Description

@picnixz

Bug report

Bug description:

hmac.digest() reaches key.ljust() with a key type its own class rejects by name, so hmac.digest(memoryview(key), msg, "md5") raises AttributeError instead of TypeError as hmac.HMAC does. I'm aligning the exceptions here but I may consider accepting other types later.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. self-assigned this
    on Aug 9, 2026
  2. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    on Aug 9, 2026
  3. added 3 commits that reference this issue on Aug 9, 2026
  4. changed the title [-]Pure-Python fallback of `hmac.digest` only accept `bytes` objects as keys[/-] [+]Raise `TypeError` in pure Python `hmac.digest` for non-bytes keys[/+] on Aug 9, 2026
  5. added 3 commits that reference this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions