mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
30103702c3
* 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
130 lines
2.5 KiB
C
130 lines
2.5 KiB
C
/*
|
|
* $Id$
|
|
* 'OpenSSL for Ruby' project
|
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
|
* All rights reserved.
|
|
*/
|
|
/*
|
|
* This program is licenced under the same licence as Ruby.
|
|
* (See the file 'LICENCE'.)
|
|
*/
|
|
#include "ossl.h"
|
|
|
|
/*
|
|
* Classes
|
|
*/
|
|
VALUE mRandom;
|
|
VALUE eRandomError;
|
|
|
|
/*
|
|
* Struct
|
|
*/
|
|
|
|
/*
|
|
* Public
|
|
*/
|
|
|
|
/*
|
|
* Private
|
|
*/
|
|
static VALUE
|
|
ossl_rand_seed(VALUE self, VALUE str)
|
|
{
|
|
StringValue(str);
|
|
RAND_seed(RSTRING(str)->ptr, RSTRING(str)->len);
|
|
|
|
return str;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_load_file(VALUE self, VALUE filename)
|
|
{
|
|
SafeStringValue(filename);
|
|
|
|
if(!RAND_load_file(RSTRING(filename)->ptr, -1)) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
return Qtrue;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_write_file(VALUE self, VALUE filename)
|
|
{
|
|
SafeStringValue(filename);
|
|
if (RAND_write_file(RSTRING(filename)->ptr) == -1) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
return Qtrue;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_bytes(VALUE self, VALUE len)
|
|
{
|
|
VALUE str;
|
|
|
|
str = rb_str_new(0, FIX2INT(len));
|
|
if (!RAND_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_pseudo_bytes(VALUE self, VALUE len)
|
|
{
|
|
VALUE str;
|
|
|
|
str = rb_str_new(0, FIX2INT(len));
|
|
if (!RAND_pseudo_bytes(RSTRING(str)->ptr, FIX2INT(len))) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_egd(VALUE self, VALUE filename)
|
|
{
|
|
SafeStringValue(filename);
|
|
|
|
if(!RAND_egd(RSTRING(filename)->ptr)) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
return Qtrue;
|
|
}
|
|
|
|
static VALUE
|
|
ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
|
|
{
|
|
SafeStringValue(filename);
|
|
|
|
if (!RAND_egd_bytes(RSTRING(filename)->ptr, FIX2INT(len))) {
|
|
ossl_raise(eRandomError, NULL);
|
|
}
|
|
return Qtrue;
|
|
}
|
|
|
|
#define DEFMETH(class, name, func, argc) \
|
|
rb_define_method(class, name, func, argc); \
|
|
rb_define_singleton_method(class, name, func, argc);
|
|
|
|
/*
|
|
* INIT
|
|
*/
|
|
void
|
|
Init_ossl_rand()
|
|
{
|
|
mRandom = rb_define_module_under(mOSSL, "Random");
|
|
|
|
eRandomError = rb_define_class_under(mRandom, "RandomError", eOSSLError);
|
|
|
|
DEFMETH(mRandom, "seed", ossl_rand_seed, 1);
|
|
DEFMETH(mRandom, "load_random_file", ossl_rand_load_file, 1);
|
|
DEFMETH(mRandom, "write_random_file", ossl_rand_write_file, 1);
|
|
DEFMETH(mRandom, "random_bytes", ossl_rand_bytes, 1);
|
|
DEFMETH(mRandom, "pseudo_bytes", ossl_rand_pseudo_bytes, 1);
|
|
DEFMETH(mRandom, "egd", ossl_rand_egd, 1);
|
|
DEFMETH(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
|
|
}
|
|
|