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

Errors in _pkcs11.pyx file: change operand "is" by "==" #145

Open
aglao83 opened this issue Nov 3, 2022 · 0 comments
Open

Errors in _pkcs11.pyx file: change operand "is" by "==" #145

aglao83 opened this issue Nov 3, 2022 · 0 comments

Comments

@aglao83
Copy link

aglao83 commented Nov 3, 2022

Hello,

There are errors in file _pkcs11.pyx that lead to a wrong behavior of the module.

In class:
cdef class MechanismWithParam under the tag "# Unpack mechanism parameters".

Please change the following:
1)
if mechanism is Mechanism.RSA_PKCS_OAEP
by
if mechanism == Mechanism.RSA_PKCS_OAEP

elif mechanism is Mechanism.AES_ECB_ENCRYPT_DATA
by
elif mechanism == Mechanism.AES_ECB_ENCRYPT_DATA

elif mechanism is Mechanism.AES_CBC_ENCRYPT_DATA
by
elif mechanism == Mechanism.AES_CBC_ENCRYPT_DATA

The "is" operand should not be used to compare enumerate and leads to wrong behavior if enumerates with large int values (>256) are compared. The best practice is to use the "==" operand instead when comparing enumerates.
This part of the code does not work as intended as the compared int values are large:
AES_ECB_ENCRYPT_DATA = 4356
AES_CBC_ENCRYPT_DATA = 4357

You can test the "is" operand problem with int value > 256 as follow:

a=5
b=5
a is b
True

a=300
b=300
a is b
False

Thanks

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

No branches or pull requests

1 participant