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

tiny functions added/implemented ( #139 ) #146

Merged
merged 5 commits into from
Jun 14, 2021
Merged

tiny functions added/implemented ( #139 ) #146

merged 5 commits into from
Jun 14, 2021

Conversation

lvntky
Copy link
Contributor

@lvntky lvntky commented Jun 13, 2021

Hi, I added 2 tiny functions due the issue #139 . I did not implement the generate_symmetric_key function because I'm not sure that I'm on the right track, and I don't want to affect the project badly. And sorry if I do something silly :) this is my first ever PR. Anyway, if the implementation goes right I can start the implementing generate_symmetric_key function similar to this function.

@chester-leung
Copy link
Member

Hi @lvntky this looks great! There's actually no need to implement a generate_symmetric_key() function in C++. The C++ should not be user facing - the user should only be calling Python functions.

We can continue to use this function, but replace the num_bytes variable with the result of calling _LIB.cipher_key_size() in Python (this calls the C++ function you wrote from Python). This is the only change necessary to fix this issue.

We should then remove the parameter from the generate_symmetric_key() function since we no longer need it to be passed in. Let me know if this makes sense or if you have any other questions!

@lvntky
Copy link
Contributor Author

lvntky commented Jun 13, 2021

hi @chester-leung thank you for this great and informative explanation. So as I understand I make only changes on generate_symmetric_key() on the core.py file right? If it is right I will start working on it ASAP. Also thank you very much for your friendly and helpful response friend 🙏

@chester-leung
Copy link
Member

@lvntky yes that's correct. You should only have to make a change in the generate_symmetric_key() function in core.py to call the C++ cipher_key_size() function you added in C++. Thank you!

@lvntky
Copy link
Contributor Author

lvntky commented Jun 14, 2021

@chester-leung thank you very much! I'm on to it then

@lvntky
Copy link
Contributor Author

lvntky commented Jun 14, 2021

hi @chester-leung I made a new contribution and small changes. I deleted the extern "C" int generate_symmetric_key(cipher_key_size()) {} in the c_api.cpp file since we don't need, and I change num_bytes variable with _LIB.cipher_key_size() in the core.py file. Sorry if I made something silly, as I said this is my first ever PR, and I really want to contribute to this project. And also thank you for your patience, informative and friendly instructions. If I made something wrong let me know and change it. Best wishes 🙏

@chester-leung
Copy link
Member

@lvntky this looks great! Left a comment.

Please also fix the build (I think you're missing a semicolon here) and also run our pre-commit hooks discussed in step 4 here to format your code.

@@ -603,7 +604,7 @@ def generate_symmetric_key(num_bytes=32):
)
return

key = AESGCM.generate_key(bit_length=num_bytes * 8)
key = AESGCM.generate_key(bit_length= _LIB.cipher_key_size() * 8)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please create a variable num_bytes and set it to _LIB.cipher_key_size() for clarity? This will add one more line but should make things easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

of course I'm doing it right now

@lvntky
Copy link
Contributor Author

lvntky commented Jun 14, 2021

hi @chester-leung I add num_byte variable end assign it to _LIB.cipher_key_size() for better readability, as you said so.

@chester-leung
Copy link
Member

Thanks! Please update us once you've fixed the build and reformatted.

@lvntky
Copy link
Contributor Author

lvntky commented Jun 14, 2021

hi @chester-leung thank you for your patience and friendly instructions. i added a semicolon to cpp function and I run the pre-commit. Also, I added some comments to functions, I can delete it if you want. But I'm a little confused about the build, should I build with docker?

@@ -591,6 +591,16 @@ def generate_symmetric_key(num_bytes=32):
num_bytes : int
Number of bytes for key
"""

"""
Due the issue #139,
Copy link
Member

Choose a reason for hiding this comment

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

Please remove these comments

src/c_api.cpp Outdated
@@ -142,3 +142,7 @@ extern "C" void opaque_decrypt_data(char **encrypted_files,
plaintext_file, key_file);
*result = status;
}

// function created for to not to allow user specifies cipher key
Copy link
Member

Choose a reason for hiding this comment

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

please remove this comment

@chester-leung
Copy link
Member

Pre-commit essentially installs some git "hooks" that will reformat your code before you commit. I'm not sure if the code has been formatted correctly - in particular, there likely shouldn't be a space between = and num_bytes here

Here are some instructions

# Install pre-commit
pip3 install pre-commit

# in the root mc2 directory, install the pre-commit hooks
pre-commit install

Then, after you make a change to the code and git add/commit, you should see the following:
image

By build, I meant these checks
image

It looks like you're passing them now, great! Eventually we'll want to also add a linter check to enforce formatting (and to ensure that all contributors have run the pre-commit formatting hooks.

@lvntky
Copy link
Contributor Author

lvntky commented Jun 14, 2021

hi @chester-leung i deleted the comments and run pre-commit. here is the screenshot:
image

@chester-leung
Copy link
Member

This looks good! Just FYI, when you run pre-commit and it modifies some files, you'll have to readd the modified files to the git staging area. Formatting looks good for now though!

Once the checks pass, we can merge this in. Thanks for your contribution @lvntky !

@chester-leung chester-leung merged commit 9104af9 into mc2-project:master Jun 14, 2021
@lvntky
Copy link
Contributor Author

lvntky commented Jun 15, 2021

thank you very much for your friendly and informative information @chester-leung i am really glad to my first contribution is for mc2. I will hunting the issues again 😄

@chester-leung
Copy link
Member

Sounds great! @lvntky if you're interested, #147 and #148 would be good to do next. Thank you again!

@lvntky
Copy link
Contributor Author

lvntky commented Jun 15, 2021

yup I am totally interested friend, i have small work into job after that i dive to them 😄

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