Skip to content

Commit 05cfcf3

Browse files
committed
Enhance printing OpenSSL versions.
* Updated the `OpenSSL::OPENSSL_VERSION_NUMBER` comment explaining the format. * Added the `OpenSSL::LIBRESSL_VERSION_NUMBER` to print LibreSSL version number, in the case that Ruby OpenSSL binding is compiled with LibreSSL. Note `test/openssl/utils.rb#libressl?` is not using this value in it for now. * Update `rake debug` to print the values in a readable way, adding `OpenSSL::OPENSSL_VERSION_NUMBER` and `OpenSSL::LIBRESSL_VERSION_NUMBER`. * Use `Rake.rake_output_message` instead of `puts` to print the message in a proper order, as well as the case of the `debug_compiler` task in the `Rakefile`.
1 parent db633c5 commit 05cfcf3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Rakefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ task :debug_compiler do
3838
end
3939

4040
task :debug do
41-
ruby "-I./lib -ropenssl -ve'puts OpenSSL::OPENSSL_VERSION, OpenSSL::OPENSSL_LIBRARY_VERSION'"
41+
ruby_code = <<~'EOF'
42+
libre_version_number_str = (defined? OpenSSL::LIBRESSL_VERSION_NUMBER) ?
43+
OpenSSL::LIBRESSL_VERSION_NUMBER.to_s(16) : "undefined"
44+
Rake.rake_output_message <<~MESSAGE
45+
OpenSSL::OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}
46+
OpenSSL::OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}
47+
OpenSSL::OPENSSL_VERSION_NUMBER: #{OpenSSL::OPENSSL_VERSION_NUMBER.to_s(16)}
48+
OpenSSL::LIBRESSL_VERSION_NUMBER: #{libre_version_number_str}
49+
MESSAGE
50+
EOF
51+
ruby %Q(-I./lib -ropenssl -rrake -ve'#{ruby_code}')
4252
end
4353

4454
task :default => :test

ext/openssl/ossl.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,10 +1149,27 @@ Init_openssl(void)
11491149

11501150
/*
11511151
* Version number of OpenSSL the ruby OpenSSL extension was built with
1152-
* (base 16)
1152+
* (base 16). The formats are below.
1153+
*
1154+
* [OpenSSL 3] <tt>0xMNN00PP0 (major minor 00 patch 0)</tt>
1155+
* [OpenSSL before 3] <tt>0xMNNFFPPS (major minor fix patch status)</tt>
1156+
* [LibreSSL] <tt>0x20000000 (fixed value)</tt>
1157+
*
1158+
* See also the man page OPENSSL_VERSION_NUMBER(3).
11531159
*/
11541160
rb_define_const(mOSSL, "OPENSSL_VERSION_NUMBER", INT2NUM(OPENSSL_VERSION_NUMBER));
11551161

1162+
#if defined(LIBRESSL_VERSION_NUMBER)
1163+
/*
1164+
* Version number of LibreSSL the ruby OpenSSL extension was built with
1165+
* (base 16). The format is <tt>0xMNNFFPPS (major minor fix patch
1166+
* status)</tt>. This constant is only defined in LibreSSL cases.
1167+
*
1168+
* See also the man page OPENSSL_VERSION_NUMBER(3).
1169+
*/
1170+
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
1171+
#endif
1172+
11561173
/*
11571174
* Boolean indicating whether OpenSSL is FIPS-capable or not
11581175
*/

0 commit comments

Comments
 (0)