aboutsummaryrefslogtreecommitdiffstats
path: root/sample/gen_csr.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2021-02-25 16:49:11 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-02-25 19:37:10 +0900
commit6a6444984bf2c388b29392e993b2c69401f208e8 (patch)
tree42bd14ff9957cf97affb1175a262d9d8e07c1caf /sample/gen_csr.rb
parenta9954bac22ba8d9f9491732f3816bc1316eaa088 (diff)
downloadruby-openssl-6a6444984bf2c388b29392e993b2c69401f208e8.tar.gz
sample: avoid "include OpenSSL"
It is not a common practice and should not be done since it causes name clash: for example, Digest and Random are provided by other standard libraries of Ruby. Fixes: https://github.com/ruby/openssl/issues/419
Diffstat (limited to 'sample/gen_csr.rb')
-rw-r--r--sample/gen_csr.rb10
1 files changed, 4 insertions, 6 deletions
diff --git a/sample/gen_csr.rb b/sample/gen_csr.rb
index 2602b68a..baac9905 100644
--- a/sample/gen_csr.rb
+++ b/sample/gen_csr.rb
@@ -3,8 +3,6 @@
require 'optparse'
require 'openssl'
-include OpenSSL
-
def usage
myname = File::basename($0)
$stderr.puts <<EOS
@@ -21,13 +19,13 @@ keyout = options["keyout"] || "keypair.pem"
$stdout.sync = true
name_str = ARGV.shift or usage()
-name = X509::Name.parse(name_str)
+name = OpenSSL::X509::Name.parse(name_str)
keypair = nil
if keypair_file
- keypair = PKey.read(File.read(keypair_file))
+ keypair = OpenSSL::PKey.read(File.read(keypair_file))
else
- keypair = PKey::RSA.new(1024) { putc "." }
+ keypair = OpenSSL::PKey::RSA.new(1024) { putc "." }
puts
puts "Writing #{keyout}..."
File.open(keyout, "w", 0400) do |f|
@@ -37,7 +35,7 @@ end
puts "Generating CSR for #{name_str}"
-req = X509::Request.new
+req = OpenSSL::X509::Request.new
req.version = 0
req.subject = name
req.public_key = keypair.public_key