-
Notifications
You must be signed in to change notification settings - Fork 171
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
rewriting most of the asn1 init code in ruby #740
Conversation
ca0ee61
to
655d144
Compare
I'm all for it! Apart from methods for accessing OpenSSL's OID registry ( It would be very nice if we can port the BER decoding code to Ruby. |
@rhenium thx for the feedback! Some follow-up where I need your input as well: If you see the ruby code, you'll find the
Essentially, the first 2 options will require a potential breaking(?) change in the ancestor chain. Not sure how you feel about that. The third option doesn't do that, at the cost of adding an additional "hidden" method. All of the above will add smth new to document (or maybe we can
You mean |
@rhenium ping for feedback. I also don't think it's possible to rewrite the decoding in ruby (or I may not have understood your suggestion). |
655d144
to
4bc0523
Compare
ext/openssl/ossl_asn1.c
Outdated
asn1data = rb_funcall(cASN1EndOfContent, rb_intern("new"), 0); | ||
else { | ||
VALUE args[4] = { value, INT2NUM(tag), Qnil, tc }; | ||
asn1data = rb_funcall3(klass, rb_intern("new"), 4, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation seems broken throughout the diff. Please set the (hard)tab size to 8 spaces and the indent size to 4 spaces in your editor (https://github.com/ruby/ruby/blob/master/.editorconfig)
ossl_asn1.c
is an old file and uses the old style of mixed tabs and spaces, but you can ignore it and use 4 spaces for indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not fixed yet. A hard tab has an equal width to 8 spaces.
I'm sorry for the delay.
Adding a class or module in the ancestor chain is normally a compatible change. Private/hidden method also seems fine. At the same time, the current diff doesn't seem to contain too much amount of code duplication to me. Please use whatever you're comfortable with. |
It uses very low-level OpenSSL functions such as |
4dc17e6
to
20e21d4
Compare
@rhenium done. |
GitHub doesn't let me add comments to the collapsed part of the diff, but we can cleanup some definitions in the C file:
|
GitHub Actions is failing with this error with Ruby 2.7, but I'm not sure why this occurs. I can't reproduce it locally. |
801cbf1
to
33ba02c
Compare
This was a bug, which was fixed in ruby 3: attr_accessor does not register I've resorted to not undeffing them in ruby 2.7 . WDYT? I'm assuming you'll be dropping 2.7 one of these days, and that's less work than figuring out a more invasive patch than this one, but I don't know if there are other implications. (there is a test asserting this accessor, which I'll have to edit if you agree). |
I haven't investigated why it raises an exception in Ruby 2.7 only, but the root cause of this particular error in Please rebase on top of master. It should now work with 2.7 too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the indentation settings in the C file.
Apart from these style issues, this looks good to me!
ext/openssl/ossl_asn1.c
Outdated
} | ||
else { | ||
VALUE args[3] = { value, INT2NUM(tag), tc }; | ||
asn1data = rb_funcall3(cASN1Data, rb_intern("new"), 3, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use rb_funcallv_public()
everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update other rb_funcall3()
usage too?
33ba02c
to
bbacdfa
Compare
Done.
I'm struggling a bit with this one. I've changed them back to tabs, as most of the rest of the file is. Isn't it correct? |
Please use 4 spaces for indentation. You can see the changed lines currently have an inconsistent indentation here: https://github.com/ruby/openssl/blob/bbacdfa19370d98212ecf2aae0eb7a9b544966e2/ext/openssl/ossl_asn1.c Historically 8 consecutive spaces of indentation was replaced by a hard tab, which is why this file contains hard tabs, but this step is not needed anymore. |
acdb64f
to
b83c64e
Compare
@rhenium hopefully it's better now. |
Yes, it looks good! Thanks. |
to have as much of the lib in ruby as possible
b83c64e
to
8305051
Compare
Merged now. Thank you! |
This is an initial proposal towards the goal of having as much of the lib in ruby as possible. While most of the code must be in C, some of the code in C is essentially calling back to ruby, and writing "ruby in C", if that makes any sense.
Lemme know what you think. I understand there may also be some cognitive load from jumping from C to ruby and back, so there's certainly a trade-off.