Skip to content

Add pyasn1 as dependency #25

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

Merged
merged 3 commits into from
Apr 14, 2022
Merged

Add pyasn1 as dependency #25

merged 3 commits into from
Apr 14, 2022

Conversation

tekktrik
Copy link
Member

@tekktrik tekktrik commented Apr 1, 2022

One of the changes from #22 that is needed a little more urgently, given that it is an unmarked and unincluded dependency for this library. Figured it was better to separate it out so it can be applied faster.

@tekktrik tekktrik requested a review from a team April 1, 2022 17:11
@FoamyGuy
Copy link
Contributor

FoamyGuy commented Apr 4, 2022

I'm not sure that I understand why this is a required dependency. Did you do some testing and run into a need for it? On a Feather RP2040 I am able to run the simpletest for this library as is without pyasn1

Here is output from successful run and lack of pyasn1

Adafruit CircuitPython 7.2.3 on 2022-03-16; Adafruit Feather RP2040 with rp2040
>>> 
>>> import adafruit_rsa
>>> import rsa_simpletest
Generating keypair...
Encrypting message...
Decrypting message...
Decrypted Message:  hello blinka
>>> import pyasn1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'pyasn1'
>>> 

Is this needed only in specific use cases or something like that?

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Apr 4, 2022

The other two scripts in examples, rsa_tests.py and rsa_sign_verify.py also seem to execute successfully on the Feather RP2040 without pyasn1

@tekktrik
Copy link
Member Author

tekktrik commented Apr 4, 2022

Ah, well glad the simpletest works. My reasoning is that key.py and asn1.py have functionalities relying on pyasn1 (which is only available on Blinka or pooooossibly using the library as is from the GitHub repo if it doesn't have its own dependencies). Since I'm not sure about the latter, this PR at least addresses the first by adding it as a dependency. But I was concerned about whether is was working as is so that's good!

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Apr 4, 2022

I'm not sure I understand the use case for this library on Blinka if there are specific parts that only work in that environment. In a CPython environment with Blinka there is the built-in module rsa that could be used instead of this library if I understand correctly.

My understanding was that this library is used only on microcontrollers normally since we don't have the core module rsa this implements a subset of it.

@tekktrik
Copy link
Member Author

tekktrik commented Apr 4, 2022

No that's a very good point. I guess then looking at the pyasn1 library maybe it should at least be made clearer in the README that certain functionality depends on the pyasn1 library. I can remove the commits to setup.py and requirements.txt in that case, and rephrase the changes to the README.

@tekktrik
Copy link
Member Author

tekktrik commented Apr 4, 2022

Would a try/except for wherever those are imported to catch the import error and transforming it be a good idea? Essentially:

try:
    import pyasn1
except ImportError as err:
    raise ImportError("This functionality requires the pyasn1 library") from err

@FoamyGuy
Copy link
Contributor

FoamyGuy commented Apr 4, 2022

Would a try/except for wherever those are imported to catch the import error and transforming it be a good idea? Essentially:

I do like this idea. This way anyone who is trying to use that functionality will get a helpful error message telling them what is wrong. But anyone not using the functionality will not end up having it get installed by pip automatically.

@tekktrik
Copy link
Member Author

tekktrik commented Apr 5, 2022

Sounds good, in that case just be aware I reverted the changes here and force pushed new changes onto the branch, based on the discussion here!

@tekktrik
Copy link
Member Author

tekktrik commented Apr 5, 2022

Wanted to keep a cleaner history :D

This was referenced Apr 5, 2022
Copy link

@askpatrickw askpatrickw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense, but I did not test.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Tested all 3 scripts in the examples folder successfully on PyPortal Titano

@FoamyGuy FoamyGuy merged commit 859dd35 into adafruit:main Apr 14, 2022
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 15, 2022
Updating https://github.com/adafruit/Adafruit_CircuitPython_MotorKit to 1.6.6 from 1.6.5:
  > Merge pull request adafruit/Adafruit_CircuitPython_MotorKit#44 from dhalbert/i2c-speed-doc
  > Update Black to latest.

Updating https://github.com/adafruit/Adafruit_CircuitPython_RSA to 1.2.7 from 1.2.6:
  > Merge pull request adafruit/Adafruit_CircuitPython_RSA#25 from tekktrik/dev/add-dependencies
  > Merge pull request adafruit/Adafruit_CircuitPython_RSA#28 from adafruit/update-badge-url
  > Update Black to latest.
  > Fixed readthedocs build
  > Consolidate Documentation sections of README
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.

3 participants