Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hmac unnecessarily restricts input to "bytes" #62440

Closed
jborgstrom mannequin opened this issue Jun 17, 2013 · 10 comments
Closed

hmac unnecessarily restricts input to "bytes" #62440

jborgstrom mannequin opened this issue Jun 17, 2013 · 10 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jborgstrom
Copy link
Mannequin

jborgstrom mannequin commented Jun 17, 2013

BPO 18240
Nosy @gpshead, @tiran
Files
  • hmac.patch: Proposed patch
  • hmac2.patch: Updated patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/tiran'
    closed_at = <Date 2013-07-01.11:09:50.812>
    created_at = <Date 2013-06-17.10:38:28.690>
    labels = ['type-feature', 'library']
    title = 'hmac unnecessarily restricts input to "bytes"'
    updated_at = <Date 2013-11-12.08:43:07.457>
    user = 'https://bugs.python.org/jborgstrom'

    bugs.python.org fields:

    activity = <Date 2013-11-12.08:43:07.457>
    actor = 'mpb'
    assignee = 'christian.heimes'
    closed = True
    closed_date = <Date 2013-07-01.11:09:50.812>
    closer = 'christian.heimes'
    components = ['Library (Lib)']
    creation = <Date 2013-06-17.10:38:28.690>
    creator = 'jborgstrom'
    dependencies = []
    files = ['30628', '30637']
    hgrepos = []
    issue_num = 18240
    keywords = ['patch']
    message_count = 10.0
    messages = ['191321', '191324', '191374', '191395', '191396', '191398', '191399', '191757', '192120', '192121']
    nosy_count = 5.0
    nosy_names = ['gregory.p.smith', 'christian.heimes', 'python-dev', 'jborgstrom', 'mpb']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18240'
    versions = ['Python 3.4']

    @jborgstrom
    Copy link
    Mannequin Author

    jborgstrom mannequin commented Jun 17, 2013

    Problem:
    In hmac.py there's a type check that verifies that the msg parameter is of type bytes().

    if not isinstance(msg, bytes):
        raise TypeError("expected bytes, but got %r" % type(msg).__name__)

    That is incorrect. The hmac module should also work with other data types as long as they are supported by the underlying hashlib module, for example bytearray() and memoryview().

    Suggestion:
    Remove that type check. hashlib will make sure str() and other invalid data types raises a TypeError.

    @jborgstrom jborgstrom mannequin added type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir labels Jun 17, 2013
    @pitrou pitrou added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Jun 17, 2013
    @tiran
    Copy link
    Member

    tiran commented Jun 17, 2013

    Good idea!

    We can also lift the restriction for key a bit. It can also take a bytearray as argument. bytearray has translate() and supports bytes + bytearay.

    @tiran tiran self-assigned this Jun 17, 2013
    @tiran
    Copy link
    Member

    tiran commented Jun 17, 2013

    Thanks for your patch! Please add tests for the new feature. The documentation needs versionchanged tags, too.

    @jborgstrom
    Copy link
    Mannequin Author

    jborgstrom mannequin commented Jun 18, 2013

    Patch updated to include tests and versionchanged tags

    @tiran
    Copy link
    Member

    tiran commented Jun 18, 2013

    Thanks for your update.

    As far as I can tell you haven't signed our contributor agreement yet. Can you please do so?

    http://www.python.org/psf/contrib/
    http://www.python.org/psf/contrib/contrib-form/

    @jborgstrom
    Copy link
    Mannequin Author

    jborgstrom mannequin commented Jun 18, 2013

    Of course. I've now signed and filed the agreement.

    @tiran
    Copy link
    Member

    tiran commented Jun 18, 2013

    It may take a day or two until your signature makes it through red tape. I'll get back to you. :)

    @tiran
    Copy link
    Member

    tiran commented Jun 24, 2013

    Your account hasn't been flagged yet. I'm going to ping the person in charge.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 1, 2013

    New changeset 636947fe131e by Christian Heimes in branch 'default':
    bpo-18240: The HMAC module is no longer restricted to bytes and accepts
    http://hg.python.org/cpython/rev/636947fe131e

    @tiran
    Copy link
    Member

    tiran commented Jul 1, 2013

    Your CLA came through and I have applied your patch. Thank you very much for your contribution!

    @tiran tiran closed this as completed Jul 1, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants