aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/lib/openssl/x509.rb
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-17 09:05:02 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-09-17 09:05:02 +0000
commit30103702c367c5cdaa18b6a622f3916cec6c701e (patch)
treec236089aa9c6b4183729735e221606a9b536d217 /ext/openssl/lib/openssl/x509.rb
parent12196ee24fce0e601106036e67526819cac07291 (diff)
downloadruby-30103702c367c5cdaa18b6a622f3916cec6c701e.tar.gz
* ext/openssl: all files are reviewed to simplify and avoid memory leak.
* ext/openssl/extconf.rb: add check for assert.h. * ext/openssl/ossl.c (ossl_buf2str): new function to convert C buffer to String and free buffer. * ext/openssl/ossl.c (ossl_x509_ary2sk): new function to convert Array of OpenSSL::X509 to STACK_OF(X509) with exception safe. * ext/openssl/ossl.c (ossl_to_der, ossl_to_der_if_possible): new functions to convert object to DER string. * ext/openssl/ossl.h: ditto. * ext/openssl/ossl_bio.c (ossl_membio2str): new function to convert BIO to String object and free BIO. * ext/openssl/ossl_bio.h: ditto. * ext/openssl/ossl_pkcs7.c (ossl_pkcs7_to_der): add for "to_der". * ext/openssl/ossl_x509name.c (ossl_x509name_to_der): ditto. * ext/openssl/ossl_x509ext.c (ossl_x509ext_to_der): ditto. * ext/openssl/ossl_x509ext.c (create_ext_from_array): removed and reimplement in openssl/x509.rb. * ext/openssl/ossl_x509attr.c: reimplemented and disable some method temporarily. this class doesn't work fine without ASN.1 data support;-) I'll rewrite in near future. * ext/openssl/lib/openssl/x509.c (X509::Attribute): get rid off unused code. * ext/openssl/lib/openssl/x509.c (X509::ExtensionFactory): refine all. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/lib/openssl/x509.rb')
-rw-r--r--ext/openssl/lib/openssl/x509.rb93
1 files changed, 14 insertions, 79 deletions
diff --git a/ext/openssl/lib/openssl/x509.rb b/ext/openssl/lib/openssl/x509.rb
index 8efe3701c8..b8cc5bd4ed 100644
--- a/ext/openssl/lib/openssl/x509.rb
+++ b/ext/openssl/lib/openssl/x509.rb
@@ -20,53 +20,29 @@
module OpenSSL
module X509
-
class ExtensionFactory
def create_extension(*arg)
- if arg.size == 1 then arg = arg[0] end
- type = arg.class
- while type
- method = "create_ext_from_#{type.name.downcase}".intern
- return send(method, arg) if respond_to? method
- type = type.superclass
+ if arg.size > 1
+ create_ext(*arg)
+ else
+ send("create_ext_from_"+arg[0].class.name.downcase, arg[0])
end
- raise TypeError, "Don't how to create ext from #{arg.class}"
- ###send("create_ext_from_#{arg.class.name.downcase}", arg)
end
- #
- # create_ext_from_array is built-in
- #
+ 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"
- unless str =~ /\s*=\s*/
- raise ArgumentError, "string in format \"oid = value\" expected"
- end
- ary = []
- ary << $`.sub(/^\s*/,"") # delete whitespaces from the beginning
- rest = $'.sub(/\s*$/,"") # delete them from the end
- if rest =~ /^critical,\s*/ # handle 'critical' option
- ary << $'
- ary << true
- else
- ary << rest
- end
- create_ext_from_array(ary)
+ oid, value = str.split(/=/, 2)
+ oid.strip!
+ value.strip!
+ create_ext(oid, value)
end
- #
- # Create an extention from Hash
- # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
- #
def create_ext_from_hash(hash)
- unless (hash.has_key? "oid" and hash.has_key? "value")
- raise ArgumentError,
- "hash in format {\"oid\"=>..., \"value\"=>...} expected"
- end
- ary = []
- ary << hash["oid"]
- ary << hash["value"]
- ary << hash["critical"] if hash.has_key? "critical"
- create_ext_from_array(ary)
+ create_ext(hash["oid"], hash["value"], hash["critical"])
end
end # ExtensionFactory
@@ -87,47 +63,6 @@ module OpenSSL
end
end # Extension
- class Attribute
- def self.new(arg)
- type = arg.class
- while type
- method = "new_from_#{type.name.downcase}".intern
- return Attribute::send(method, arg) if Attribute::respond_to? method
- type = type.superclass
- end
- raise "Don't how to make new #{self} from #{arg.class}"
- ###Attribute::send("new_from_#{arg.class.name.downcase}", arg)
- end
-
- #
- # Attribute::new_from_array(ary) is built-in method
- #
- def Attribute::new_from_string(str) # "oid = value"
- unless str =~ /\s*=\s*/
- raise ArgumentError, "string in format \"oid = value\" expected"
- end
- ary = []
- ary << $`.sub(/^\s*/,"") # delete whitespaces from the beginning
- ary << $'.sub(/\s*$/,"") # delete them from the end
- Attribute::new_from_array(ary)
- end
-
- #
- # Create an attribute from Hash
- # {"oid"=>sn|ln, "value"=>value, "critical"=>true|false}
- #
- def Attribute::new_from_hash(hash) # {"oid"=>"...", "value"=>"..."}
- unless (hash.has_key? "oid" and hash.has_key? "value")
- raise ArgumentError,
- "hash in format {\"oid\"=>..., \"value\"=>...} expected"
- end
- ary = []
- ary << hash["oid"]
- ary << hash["value"]
- Attribute::new_from_array(ary)
- end
- end # Attribute
-
class Name
def self.parse(str)
ary = str.scan(/\s*([^\/,]+)\s*/).collect{|i| i[0].split("=") }