mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

second argument. it expected to be a Hash not an Integer. * ext/openssl/ossl_x509name.c (ossl_x509name_add_entry): add new function for OpenSSL::X509::Name#add_entry. * ext/openssl/ossl_x509name.c (Init_ossl_x509name): add constants OpenSSL::X509::Name::DEFAULT_OBJECT_TYPE and OBJECT_TYPE_TEMPLATE. * ext/openssl/lib/openssl/x509.rb (OpenSSL::X509::Name#initialize): second argument takes OBJECT_TYPE_TEMPLATE by default. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
71 lines
1.7 KiB
Ruby
71 lines
1.7 KiB
Ruby
=begin
|
|
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses
|
|
|
|
= Info
|
|
'OpenSSL for Ruby 2' project
|
|
Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
All rights reserved.
|
|
|
|
= Licence
|
|
This program is licenced under the same licence as Ruby.
|
|
(See the file 'LICENCE'.)
|
|
|
|
= Version
|
|
$Id$
|
|
=end
|
|
|
|
require "openssl"
|
|
|
|
module OpenSSL
|
|
module X509
|
|
class ExtensionFactory
|
|
def create_extension(*arg)
|
|
if arg.size > 1
|
|
create_ext(*arg)
|
|
else
|
|
send("create_ext_from_"+arg[0].class.name.downcase, arg[0])
|
|
end
|
|
end
|
|
|
|
def create_ext_from_array(ary)
|
|
raise ExtensionError, "unexpected array form" if ary.size > 3
|
|
create_ext(ary[0], ary[1], ary[2])
|
|
end
|
|
|
|
def create_ext_from_string(str) # "oid = critical, value"
|
|
oid, value = str.split(/=/, 2)
|
|
oid.strip!
|
|
value.strip!
|
|
create_ext(oid, value)
|
|
end
|
|
|
|
def create_ext_from_hash(hash)
|
|
create_ext(hash["oid"], hash["value"], hash["critical"])
|
|
end
|
|
end
|
|
|
|
class Extension
|
|
def to_s # "oid = critical, value"
|
|
str = self.oid
|
|
str << " = "
|
|
str << "critical, " if self.critical?
|
|
str << self.value.gsub(/\n/, ", ")
|
|
end
|
|
|
|
def to_h # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
|
|
{"oid"=>self.oid,"value"=>self.value,"critical"=>self.critical?}
|
|
end
|
|
|
|
def to_a
|
|
[ self.oid, self.value, self.critical? ]
|
|
end
|
|
end
|
|
|
|
class Name
|
|
def self.parse(str, template=OBJECT_TYPE_TEMPLATE)
|
|
ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=", 2) }
|
|
self.new(ary, template)
|
|
end
|
|
end
|
|
end
|
|
end
|