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

Enhance printing OpenSSL versions. #662

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ task :debug_compiler do
end

task :debug do
ruby "-I./lib -ropenssl -ve'puts OpenSSL::OPENSSL_VERSION, OpenSSL::OPENSSL_LIBRARY_VERSION'"
ruby_code = <<~'EOF'
openssl_version_number_str = OpenSSL::OPENSSL_VERSION_NUMBER.to_s(16)
libressl_version_number_str = (defined? OpenSSL::LIBRESSL_VERSION_NUMBER) ?
OpenSSL::LIBRESSL_VERSION_NUMBER.to_s(16) : "undefined"
puts <<~MESSAGE
OpenSSL::OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}
OpenSSL::OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}
OpenSSL::OPENSSL_VERSION_NUMBER: #{openssl_version_number_str}
OpenSSL::LIBRESSL_VERSION_NUMBER: #{libressl_version_number_str}
MESSAGE
EOF
ruby %Q(-I./lib -ropenssl -ve'#{ruby_code}')
junaruga marked this conversation as resolved.
Show resolved Hide resolved
end

task :default => :test
19 changes: 18 additions & 1 deletion ext/openssl/ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,27 @@ Init_openssl(void)

/*
* Version number of OpenSSL the ruby OpenSSL extension was built with
* (base 16)
* (base 16). The formats are below.
*
* [OpenSSL 3] <tt>0xMNN00PP0 (major minor 00 patch 0)</tt>
* [OpenSSL before 3] <tt>0xMNNFFPPS (major minor fix patch status)</tt>
* [LibreSSL] <tt>0x20000000 (fixed value)</tt>
*
* See also the man page OPENSSL_VERSION_NUMBER(3).
*/
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));

#if defined(LIBRESSL_VERSION_NUMBER)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note the reason why the #if defined(LIBRESSL_VERSION_NUMBER) is above the comment, not below the comment is because Rdoc cannot parse the comment if #if defined(LIBRESSL_VERSION_NUMBER) is written below the comment.

/*
* Version number of LibreSSL the ruby OpenSSL extension was built with
* (base 16). The format is <tt>0xMNNFFPPS (major minor fix patch
* status)</tt>. This constant is only defined in LibreSSL cases.
*
* See also the man page OPENSSL_VERSION_NUMBER(3).
*/
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
#endif
junaruga marked this conversation as resolved.
Show resolved Hide resolved

/*
* Boolean indicating whether OpenSSL is FIPS-capable or not
*/
Expand Down