From 9bf2911d74cc5b6d8697acb6ed4e6c39b2b74f1e Mon Sep 17 00:00:00 2001 From: nahi Date: Thu, 4 Sep 2003 10:31:29 +0000 Subject: * sample/openssl: added. Sample of standard distribution library should be locate in sample/{module_name}/*. * ext/openssl/sample/*: removed. move to sample/openssl/*. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@4492 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sample/openssl/cert2text.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 sample/openssl/cert2text.rb (limited to 'sample/openssl/cert2text.rb') diff --git a/sample/openssl/cert2text.rb b/sample/openssl/cert2text.rb new file mode 100644 index 000000000..50da224e7 --- /dev/null +++ b/sample/openssl/cert2text.rb @@ -0,0 +1,23 @@ +#!/usr/bin/env ruby + +require 'openssl' +include OpenSSL::X509 + +def cert2text(cert_str) + [Certificate, CRL, Request].each do |klass| + begin + puts klass.new(cert_str).to_text + return + rescue + end + end + raise ArgumentError.new('Unknown format.') +end + +if ARGV.empty? + cert2text(STDIN.read) +else + ARGV.each do |file| + cert2text(File.read(file)) + end +end -- cgit