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

rewriting most of the asn1 init code in ruby #740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HoneyryderChuck
Copy link

@HoneyryderChuck HoneyryderChuck commented Apr 16, 2024

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.

lib/openssl/asn1.rb Outdated Show resolved Hide resolved
ext/openssl/ossl_asn1.c Outdated Show resolved Hide resolved
to have as much of the lib in ruby as possible
@rhenium
Copy link
Member

rhenium commented Apr 26, 2024

I'm all for it!

Apart from methods for accessing OpenSSL's OID registry (OpenSSL::ASN1::ObjectID.register, #sn, #ln, and #oid), OpenSSL::ASN1 could have been entirely written in Ruby, and that would definitely make maintenance easier.

It would be very nice if we can port the BER decoding code to Ruby.

@HoneyryderChuck
Copy link
Author

@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 initialize method copy-pasted both for Primitive and Constructive, which is a direct port from the deleted C code, where both classes were sharing the same underlying impl in C. I'd like to address, and I can see the following options:

  • Create base class for both, inheriting from ASN1Data, which implements common initialize;
  • Create module with initialize, inject on both classes;
  • Create __initialize_with.. method in ASN1Data class, call for both on initialize;

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 :nodoc: all of them?). Which one do you think suits this the best?

It would be very nice if we can port the BER decoding code to Ruby.

You mean OpenSSL::ASN1.decode? I can try, but AFAIR there was some dependency on some openssl function calls, so don't know how feasible will that be.

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

Successfully merging this pull request may close these issues.

None yet

3 participants