Skip to content

Hmac working without generics, and test not working yet - #5652

Open
Shakil582 wants to merge 2 commits into
RustPython:mainfrom
Shakil582:main
Open

Hmac working without generics, and test not working yet#5652
Shakil582 wants to merge 2 commits into
RustPython:mainfrom
Shakil582:main

Conversation

@Shakil582

@Shakil582 Shakil582 commented Apr 1, 2025

Copy link
Copy Markdown

This is a draft PR just to show what I have so far, the things I want to do before pulling in the PR are:

  1. Get the unit tests of test_hmac.py working
  2. make a generic function to use within the new_hash_hmac() functions for initialization, I just tried very hard to have it work like the hashlib stuff using generics, but I think because CoreProxy needs a type at compile time I can't initialize an hmac dynamically like it's being done for the HashWrapper. Might still play around with that a little, and if anyone know's a way I can use generics I would appreciate the advice, but I couldn't find a way to do it without having to pass a generic to HmacWrapper (as in it would have to be HmacWrapper which then I don't think I can use in PyHmac because I'm guessing it needs to be generic free for the front end).
  3. Play around with NewHmacHashArgs since I get an error when trying to initialize hmac without msg, and digestmod should be able to take a function. I have a feeling the msg thing might be something deeper because it complains about the function in hmac.py expecting 0 arguments.

Other than that, playing with what I have vs the cpython version they output the same bytes when digesting.

@Shakil582
Shakil582 force-pushed the main branch 2 times, most recently from 9bbb4f6 to b54f0ca Compare April 7, 2025 11:58
@arihant2math

arihant2math commented Apr 8, 2025

Copy link
Copy Markdown
Contributor

Running cargo fmt will fix part of the "Check Rust code with rustfmt and clippy" check.
Running the following and fixing all errors/warnings should fix the other tests:

cargo clippy --workspace --all-targets

@Shakil582

Copy link
Copy Markdown
Author

Will do, I've been procrastinating it for a bit since I'm trying to get passing digestmod functions as arguments working. Hopefully, it should be up and done this weekend.

@Shakil582

Shakil582 commented Apr 12, 2025

Copy link
Copy Markdown
Author

So I gave up on passing in function for a bit since HmacCore requires strict traits on the class passed into it's generic. Maybe functions can be easily done if we make the function name public and pass in the relevant hash function into it depending on the function name, but that might not be worth it since I'm sure there's reasons not to make pyfunction names public, and also it would only work for the specific hashlib hash functions. I guess the options potentially are an HmacCore rewrite where we don't require as strict compile time checks on the passed hash function, or maybe there is a way to use generics that I'm just not that familiar with rust to see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants