Skip to content

Commit ff14d38

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. The value is `nil` in the OpenSSL case. Note `test/openssl/utils.rb#libressl?` is not using this value in it. * Update `rake debug` to print the values in a readable way, adding `OpenSSL::OPENSSL_VERSION_NUMBER` and `OpenSSL::LIBRESSL_VERSION_NUMBER`.
1 parent db633c5 commit ff14d38

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
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 = (!OpenSSL::LIBRESSL_VERSION_NUMBER.nil?) ?
43+
OpenSSL::LIBRESSL_VERSION_NUMBER.to_s(16) : "nil"
44+
puts <<~'MSG'
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+
MSG
50+
EOF
51+
ruby %Q(-I./lib -ropenssl -ve'#{ruby_code}')
4252
end
4353

4454
task :default => :test

ext/openssl/ossl.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,29 @@ Init_openssl(void)
11501150
/*
11511151
* Version number of OpenSSL the ruby OpenSSL extension was built with
11521152
* (base 16)
1153+
*
1154+
* OpenSSL 3: 0xMNN00PP0 (major minor 00 patch 0)
1155+
* OpenSSL 1: 0xMNNFFPPS (major minor fix patch status)
1156+
* LibreSSL : 0x20000000 (fixed value)
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+
/*
1163+
* Version number of LibreSSL the ruby OpenSSL extension was built with
1164+
* (base 16)
1165+
*
1166+
* LibreSSL: 0xMNNFFPPS (major minor fix patch status)
1167+
*
1168+
* See also the man page OPENSSL_VERSION_NUMBER(3).
1169+
*/
1170+
#if defined(LIBRESSL_VERSION_NUMBER)
1171+
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", INT2NUM(LIBRESSL_VERSION_NUMBER));
1172+
#else
1173+
rb_define_const(mOSSL, "LIBRESSL_VERSION_NUMBER", Qnil);
1174+
#endif
1175+
11561176
/*
11571177
* Boolean indicating whether OpenSSL is FIPS-capable or not
11581178
*/

0 commit comments

Comments
 (0)