* lib/set.rb (Set#==): [ruby-dev:25206]

* ext/openssl/ossl_digest.c (ossl_digest_initialize): [ruby-dev:25198]

* utf8.c (utf8_is_mbc_ambiguous): [ruby-talk:123561]

* utf8.c (utf8_mbc_to_normalize): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7563 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-12-15 06:35:55 +00:00
Родитель 772396882f
Коммит 2edbb9d0f8
23 изменённых файлов: 184 добавлений и 146 удалений

Просмотреть файл

@ -1,7 +1,15 @@
Wed Dec 15 15:31:02 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* lib/set.rb (Set#==): [ruby-dev:25206]
Wed Dec 15 14:32:18 2004 NAKAMURA Usaku <usa@ruby-lang.org> Wed Dec 15 14:32:18 2004 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/win32.c (rb_w32_fdisset): check whether the handle is valid. * win32/win32.c (rb_w32_fdisset): check whether the handle is valid.
Wed Dec 15 10:30:37 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* ext/openssl/ossl_digest.c (ossl_digest_initialize): [ruby-dev:25198]
Tue Dec 14 19:17:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org> Tue Dec 14 19:17:15 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* utf8.c (utf8_is_mbc_ambiguous): [ruby-talk:123561] * utf8.c (utf8_is_mbc_ambiguous): [ruby-talk:123561]

Просмотреть файл

@ -107,11 +107,11 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
VALUE str, bs; VALUE str, bs;
int base = 10; int base = 10;
GetBN(self, bn);
if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) { if (rb_scan_args(argc, argv, "11", &str, &bs) == 2) {
base = NUM2INT(bs); base = NUM2INT(bs);
} }
StringValue(str);
GetBN(self, bn);
if (RTEST(rb_obj_is_kind_of(str, cBN))) { if (RTEST(rb_obj_is_kind_of(str, cBN))) {
BIGNUM *other; BIGNUM *other;
@ -121,8 +121,6 @@ ossl_bn_initialize(int argc, VALUE *argv, VALUE self)
} }
return self; return self;
} }
str = rb_String(str);
StringValue(str);
switch (base) { switch (base) {
case 0: case 0:
@ -159,11 +157,10 @@ ossl_bn_to_s(int argc, VALUE *argv, VALUE self)
int base = 10, len; int base = 10, len;
char *buf; char *buf;
GetBN(self, bn);
if (rb_scan_args(argc, argv, "01", &bs) == 1) { if (rb_scan_args(argc, argv, "01", &bs) == 1) {
base = NUM2INT(bs); base = NUM2INT(bs);
} }
GetBN(self, bn);
switch (base) { switch (base) {
case 0: case 0:
len = BN_bn2mpi(bn, NULL); len = BN_bn2mpi(bn, NULL);
@ -380,11 +377,12 @@ BIGNUM_BIT(mask_bits);
static VALUE static VALUE
ossl_bn_is_bit_set(VALUE self, VALUE bit) ossl_bn_is_bit_set(VALUE self, VALUE bit)
{ {
int b;
BIGNUM *bn; BIGNUM *bn;
b = NUM2INT(bit);
GetBN(self, bn); GetBN(self, bn);
if (BN_is_bit_set(bn, b)) {
if (BN_is_bit_set(bn, NUM2INT(bit))) {
return Qtrue; return Qtrue;
} }
return Qfalse; return Qfalse;
@ -397,8 +395,8 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
BIGNUM *bn, *result; \ BIGNUM *bn, *result; \
int b; \ int b; \
VALUE obj; \ VALUE obj; \
GetBN(self, bn); \
b = NUM2INT(bits); \ b = NUM2INT(bits); \
GetBN(self, bn); \
if (!(result = BN_new())) { \ if (!(result = BN_new())) { \
ossl_raise(eBNError, NULL); \ ossl_raise(eBNError, NULL); \
} \ } \
@ -550,11 +548,10 @@ ossl_bn_is_prime(int argc, VALUE *argv, VALUE self)
VALUE vchecks; VALUE vchecks;
int checks = BN_prime_checks; int checks = BN_prime_checks;
GetBN(self, bn);
if (rb_scan_args(argc, argv, "01", &vchecks) == 0) { if (rb_scan_args(argc, argv, "01", &vchecks) == 0) {
checks = NUM2INT(vchecks); checks = NUM2INT(vchecks);
} }
GetBN(self, bn);
switch (BN_is_prime(bn, checks, NULL, ossl_bn_ctx, NULL)) { switch (BN_is_prime(bn, checks, NULL, ossl_bn_ctx, NULL)) {
case 1: case 1:
return Qtrue; return Qtrue;
@ -574,13 +571,12 @@ ossl_bn_is_prime_fasttest(int argc, VALUE *argv, VALUE self)
VALUE vchecks, vtrivdiv; VALUE vchecks, vtrivdiv;
int checks = BN_prime_checks, do_trial_division = 1; int checks = BN_prime_checks, do_trial_division = 1;
GetBN(self, bn);
rb_scan_args(argc, argv, "02", &vchecks, &vtrivdiv); rb_scan_args(argc, argv, "02", &vchecks, &vtrivdiv);
if (!NIL_P(vchecks)) { if (!NIL_P(vchecks)) {
checks = NUM2INT(vchecks); checks = NUM2INT(vchecks);
} }
GetBN(self, bn);
/* handle true/false */ /* handle true/false */
if (vtrivdiv == Qfalse) { if (vtrivdiv == Qfalse) {
do_trial_division = 0; do_trial_division = 0;

Просмотреть файл

@ -91,10 +91,8 @@ ossl_cipher_initialize(VALUE self, VALUE str)
const EVP_CIPHER *cipher; const EVP_CIPHER *cipher;
char *name; char *name;
GetCipher(self, ctx);
name = StringValuePtr(str); name = StringValuePtr(str);
GetCipher(self, ctx);
if (!(cipher = EVP_get_cipherbyname(name))) { if (!(cipher = EVP_get_cipherbyname(name))) {
ossl_raise(rb_eRuntimeError, "Unsupported cipher algorithm (%s).", name); ossl_raise(rb_eRuntimeError, "Unsupported cipher algorithm (%s).", name);
} }
@ -139,7 +137,6 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
unsigned char iv[EVP_MAX_IV_LENGTH], *p_iv = NULL; unsigned char iv[EVP_MAX_IV_LENGTH], *p_iv = NULL;
VALUE pass, init_v; VALUE pass, init_v;
GetCipher(self, ctx);
if(rb_scan_args(argc, argv, "02", &pass, &init_v) > 0){ if(rb_scan_args(argc, argv, "02", &pass, &init_v) > 0){
/* /*
* oops. this code mistakes salt for IV. * oops. this code mistakes salt for IV.
@ -147,6 +144,7 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
* keeping this behaviour for backward compatibility. * keeping this behaviour for backward compatibility.
*/ */
StringValue(pass); StringValue(pass);
GetCipher(self, ctx);
if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv)); if (NIL_P(init_v)) memcpy(iv, "OpenSSL for Ruby rulez!", sizeof(iv));
else{ else{
char *cname = rb_class2name(rb_obj_class(self)); char *cname = rb_class2name(rb_obj_class(self));
@ -164,6 +162,9 @@ ossl_cipher_init(int argc, VALUE *argv, VALUE self, int mode)
p_key = key; p_key = key;
p_iv = iv; p_iv = iv;
} }
else {
GetCipher(self, ctx);
}
if (EVP_CipherInit_ex(ctx, NULL, NULL, p_key, p_iv, mode) != 1) { if (EVP_CipherInit_ex(ctx, NULL, NULL, p_key, p_iv, mode) != 1) {
ossl_raise(eCipherError, NULL); ossl_raise(eCipherError, NULL);
} }
@ -192,7 +193,6 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH], *salt = NULL; unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH], *salt = NULL;
int iter; int iter;
GetCipher(self, ctx);
rb_scan_args(argc, argv, "13", &vpass, &vsalt, &viter, &vdigest); rb_scan_args(argc, argv, "13", &vpass, &vsalt, &viter, &vdigest);
StringValue(vpass); StringValue(vpass);
if(!NIL_P(vsalt)){ if(!NIL_P(vsalt)){
@ -203,6 +203,7 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
} }
iter = NIL_P(viter) ? 2048 : NUM2INT(viter); iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest); digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest);
GetCipher(self, ctx);
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt, EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
RSTRING(vpass)->ptr, RSTRING(vpass)->len, iter, key, iv); RSTRING(vpass)->ptr, RSTRING(vpass)->len, iter, key, iv);
if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1) if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, -1) != 1)
@ -221,10 +222,10 @@ ossl_cipher_update(VALUE self, VALUE data)
int in_len, out_len; int in_len, out_len;
VALUE str; VALUE str;
GetCipher(self, ctx);
StringValue(data); StringValue(data);
in = RSTRING(data)->ptr; in = RSTRING(data)->ptr;
in_len = RSTRING(data)->len; in_len = RSTRING(data)->len;
GetCipher(self, ctx);
str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx)); str = rb_str_new(0, in_len+EVP_CIPHER_CTX_block_size(ctx));
if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len)) if (!EVP_CipherUpdate(ctx, RSTRING(str)->ptr, &out_len, in, in_len))
ossl_raise(eCipherError, NULL); ossl_raise(eCipherError, NULL);
@ -300,10 +301,11 @@ ossl_cipher_set_iv(VALUE self, VALUE iv)
static VALUE static VALUE
ossl_cipher_set_key_length(VALUE self, VALUE key_length) ossl_cipher_set_key_length(VALUE self, VALUE key_length)
{ {
int len = NUM2INT(key_length);
EVP_CIPHER_CTX *ctx; EVP_CIPHER_CTX *ctx;
GetCipher(self, ctx); GetCipher(self, ctx);
if (EVP_CIPHER_CTX_set_key_length(ctx, NUM2INT(key_length)) != 1) if (EVP_CIPHER_CTX_set_key_length(ctx, len) != 1)
ossl_raise(eCipherError, NULL); ossl_raise(eCipherError, NULL);
return key_length; return key_length;
@ -314,9 +316,10 @@ ossl_cipher_set_padding(VALUE self, VALUE padding)
{ {
#if defined(HAVE_EVP_CIPHER_CTX_SET_PADDING) #if defined(HAVE_EVP_CIPHER_CTX_SET_PADDING)
EVP_CIPHER_CTX *ctx; EVP_CIPHER_CTX *ctx;
int pad = NUM2INT(padding);
GetCipher(self, ctx); GetCipher(self, ctx);
if (EVP_CIPHER_CTX_set_padding(ctx, NUM2INT(padding)) != 1) if (EVP_CIPHER_CTX_set_padding(ctx, pad) != 1)
ossl_raise(eCipherError, NULL); ossl_raise(eCipherError, NULL);
#else #else
rb_notimplement(); rb_notimplement();

Просмотреть файл

@ -119,8 +119,8 @@ ossl_config_copy(VALUE self, VALUE other)
VALUE str; VALUE str;
CONF *conf; CONF *conf;
GetConfig(other, conf);
str = rb_funcall(self, rb_intern("to_s"), 0); str = rb_funcall(self, rb_intern("to_s"), 0);
GetConfig(other, conf);
parse_config(str, conf); parse_config(str, conf);
return self; return self;
@ -134,11 +134,11 @@ ossl_config_initialize(int argc, VALUE *argv, VALUE self)
char *filename; char *filename;
VALUE path; VALUE path;
GetConfig(self, conf);
rb_scan_args(argc, argv, "01", &path); rb_scan_args(argc, argv, "01", &path);
if(!NIL_P(path)){ if(!NIL_P(path)){
SafeStringValue(path); SafeStringValue(path);
filename = StringValuePtr(path); filename = StringValuePtr(path);
GetConfig(self, conf);
if (!NCONF_load(conf, filename, &eline)){ if (!NCONF_load(conf, filename, &eline)){
if (eline <= 0) if (eline <= 0)
ossl_raise(eConfigError, "wrong config file %s", filename); ossl_raise(eConfigError, "wrong config file %s", filename);
@ -149,7 +149,10 @@ ossl_config_initialize(int argc, VALUE *argv, VALUE self)
#ifdef OSSL_NO_CONF_API #ifdef OSSL_NO_CONF_API
else rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)"); else rb_raise(rb_eArgError, "wrong number of arguments (0 for 1)");
#else #else
else _CONF_new_data(conf); else {
GetConfig(self, conf);
_CONF_new_data(conf);
}
#endif #endif
return self; return self;
@ -164,10 +167,10 @@ ossl_config_add_value(VALUE self, VALUE section, VALUE name, VALUE value)
CONF *conf; CONF *conf;
CONF_VALUE *sv, *cv; CONF_VALUE *sv, *cv;
GetConfig(self, conf);
StringValue(section); StringValue(section);
StringValue(name); StringValue(name);
StringValue(value); StringValue(value);
GetConfig(self, conf);
if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){ if(!(sv = _CONF_get_section(conf, RSTRING(section)->ptr))){
if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){ if(!(sv = _CONF_new_section(conf, RSTRING(section)->ptr))){
ossl_raise(eConfigError, NULL); ossl_raise(eConfigError, NULL);
@ -195,9 +198,9 @@ ossl_config_get_value(VALUE self, VALUE section, VALUE name)
CONF *conf; CONF *conf;
char *str; char *str;
GetConfig(self, conf);
StringValue(section); StringValue(section);
StringValue(name); StringValue(name);
GetConfig(self, conf);
str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr); str = NCONF_get_string(conf, RSTRING(section)->ptr, RSTRING(name)->ptr);
if(!str){ if(!str){
ERR_clear_error(); ERR_clear_error();
@ -261,6 +264,7 @@ ossl_config_get_section(VALUE self, VALUE section)
VALUE hash; VALUE hash;
hash = rb_hash_new(); hash = rb_hash_new();
StringValue(section);
GetConfig(self, conf); GetConfig(self, conf);
if (!(sk = NCONF_get_section(conf, StringValuePtr(section)))) { if (!(sk = NCONF_get_section(conf, StringValuePtr(section)))) {
ERR_clear_error(); ERR_clear_error();

Просмотреть файл

@ -85,16 +85,16 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
char *name; char *name;
VALUE type, data; VALUE type, data;
GetDigest(self, ctx);
rb_scan_args(argc, argv, "11", &type, &data); rb_scan_args(argc, argv, "11", &type, &data);
name = StringValuePtr(type); StringValue(type);
if (!NIL_P(data)) StringValue(data); if (!NIL_P(data)) StringValue(data);
name = StringValuePtr(type);
md = EVP_get_digestbyname(name); md = EVP_get_digestbyname(name);
if (!md) { if (!md) {
ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name); ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
} }
GetDigest(self, ctx);
EVP_DigestInit_ex(ctx, md, NULL); EVP_DigestInit_ex(ctx, md, NULL);
if (!NIL_P(data)) return ossl_digest_update(self, data); if (!NIL_P(data)) return ossl_digest_update(self, data);
@ -134,8 +134,8 @@ ossl_digest_update(VALUE self, VALUE data)
{ {
EVP_MD_CTX *ctx; EVP_MD_CTX *ctx;
GetDigest(self, ctx);
StringValue(data); StringValue(data);
GetDigest(self, ctx);
EVP_DigestUpdate(ctx, RSTRING(data)->ptr, RSTRING(data)->len); EVP_DigestUpdate(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self; return self;
@ -218,13 +218,13 @@ ossl_digest_equal(VALUE self, VALUE other)
EVP_MD_CTX *ctx; EVP_MD_CTX *ctx;
VALUE str1, str2; VALUE str1, str2;
GetDigest(self, ctx);
if (rb_obj_is_kind_of(other, cDigest) == Qtrue) { if (rb_obj_is_kind_of(other, cDigest) == Qtrue) {
str2 = ossl_digest_digest(other); str2 = ossl_digest_digest(other);
} else { } else {
StringValue(other); StringValue(other);
str2 = other; str2 = other;
} }
GetDigest(self, ctx);
if (RSTRING(str2)->len == EVP_MD_CTX_size(ctx)) { if (RSTRING(str2)->len == EVP_MD_CTX_size(ctx)) {
str1 = ossl_digest_digest(self); str1 = ossl_digest_digest(self);
} else { } else {

Просмотреть файл

@ -253,9 +253,10 @@ static VALUE
ossl_engine_set_default(VALUE self, VALUE flag) ossl_engine_set_default(VALUE self, VALUE flag)
{ {
ENGINE *e; ENGINE *e;
int f = NUM2INT(flag);
GetEngine(self, e); GetEngine(self, e);
ENGINE_set_default(e, NUM2INT(flag)); ENGINE_set_default(e, f);
return Qtrue; return Qtrue;
} }

Просмотреть файл

@ -62,8 +62,8 @@ ossl_hmac_initialize(VALUE self, VALUE key, VALUE digest)
{ {
HMAC_CTX *ctx; HMAC_CTX *ctx;
GetHMAC(self, ctx);
StringValue(key); StringValue(key);
GetHMAC(self, ctx);
HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len, HMAC_Init_ex(ctx, RSTRING(key)->ptr, RSTRING(key)->len,
GetDigestPtr(digest), NULL); GetDigestPtr(digest), NULL);
@ -92,8 +92,8 @@ ossl_hmac_update(VALUE self, VALUE data)
{ {
HMAC_CTX *ctx; HMAC_CTX *ctx;
GetHMAC(self, ctx);
StringValue(data); StringValue(data);
GetHMAC(self, ctx);
HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len); HMAC_Update(ctx, RSTRING(data)->ptr, RSTRING(data)->len);
return self; return self;

Просмотреть файл

@ -172,9 +172,9 @@ ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
EVP_PKEY *pkey; EVP_PKEY *pkey;
const EVP_MD *md; const EVP_MD *md;
GetSPKI(self, spki);
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
md = GetDigestPtr(digest); md = GetDigestPtr(digest);
GetSPKI(self, spki);
if (!NETSCAPE_SPKI_sign(spki, pkey, md)) { if (!NETSCAPE_SPKI_sign(spki, pkey, md)) {
ossl_raise(eSPKIError, NULL); ossl_raise(eSPKIError, NULL);
} }

Просмотреть файл

@ -127,11 +127,13 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
int ret; int ret;
rb_scan_args(argc, argv, "01", &val); rb_scan_args(argc, argv, "01", &val);
GetOCSPReq(self, req); if(NIL_P(val)) {
if(NIL_P(val)) GetOCSPReq(self, req);
ret = OCSP_request_add1_nonce(req, NULL, -1); ret = OCSP_request_add1_nonce(req, NULL, -1);
}
else{ else{
StringValue(val); StringValue(val);
GetOCSPReq(self, req);
ret = OCSP_request_add1_nonce(req, RSTRING(val)->ptr, RSTRING(val)->len); ret = OCSP_request_add1_nonce(req, RSTRING(val)->ptr, RSTRING(val)->len);
} }
if(!ret) ossl_raise(eOCSPError, NULL); if(!ret) ossl_raise(eOCSPError, NULL);
@ -214,7 +216,6 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
int ret; int ret;
rb_scan_args(argc, argv, "22", &signer_cert, &signer_key, &certs, &flags); rb_scan_args(argc, argv, "22", &signer_cert, &signer_key, &certs, &flags);
GetOCSPReq(self, req);
signer = GetX509CertPtr(signer_cert); signer = GetX509CertPtr(signer_cert);
key = GetPrivPKeyPtr(signer_key); key = GetPrivPKeyPtr(signer_key);
flg = NIL_P(flags) ? 0 : NUM2INT(flags); flg = NIL_P(flags) ? 0 : NUM2INT(flags);
@ -223,6 +224,7 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
flags |= OCSP_NOCERTS; flags |= OCSP_NOCERTS;
} }
else x509s = ossl_x509_ary2sk(certs); else x509s = ossl_x509_ary2sk(certs);
GetOCSPReq(self, req);
ret = OCSP_request_sign(req, signer, key, EVP_sha1(), x509s, flg); ret = OCSP_request_sign(req, signer, key, EVP_sha1(), x509s, flg);
sk_X509_pop_free(x509s, X509_free); sk_X509_pop_free(x509s, X509_free);
if(!ret) ossl_raise(eOCSPError, NULL); if(!ret) ossl_raise(eOCSPError, NULL);
@ -240,10 +242,10 @@ ossl_ocspreq_verify(int argc, VALUE *argv, VALUE self)
int flg, result; int flg, result;
rb_scan_args(argc, argv, "21", &certs, &store, &flags); rb_scan_args(argc, argv, "21", &certs, &store, &flags);
GetOCSPReq(self, req);
x509st = GetX509StorePtr(store); x509st = GetX509StorePtr(store);
flg = NIL_P(flags) ? 0 : INT2NUM(flags); flg = NIL_P(flags) ? 0 : INT2NUM(flags);
x509s = ossl_x509_ary2sk(certs); x509s = ossl_x509_ary2sk(certs);
GetOCSPReq(self, req);
result = OCSP_request_verify(req, x509s, x509st, flg); result = OCSP_request_verify(req, x509s, x509st, flg);
sk_X509_pop_free(x509s, X509_free); sk_X509_pop_free(x509s, X509_free);
if(!result) rb_warn("%s", ERR_error_string(ERR_peek_error(), NULL)); if(!result) rb_warn("%s", ERR_error_string(ERR_peek_error(), NULL));
@ -259,12 +261,11 @@ ossl_ocspreq_to_der(VALUE self)
unsigned char *p; unsigned char *p;
long len; long len;
GetOCSPReq(self, req);
if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0) if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0)
ossl_raise(eOCSPError, NULL); ossl_raise(eOCSPError, NULL);
str = rb_str_new(0, len); str = rb_str_new(0, len);
p = RSTRING(str)->ptr; p = RSTRING(str)->ptr;
GetOCSPReq(self, req);
if(i2d_OCSP_REQUEST(req, &p) <= 0) if(i2d_OCSP_REQUEST(req, &p) <= 0)
ossl_raise(eOCSPError, NULL); ossl_raise(eOCSPError, NULL);
ossl_str_adjust(str, p); ossl_str_adjust(str, p);
@ -281,10 +282,11 @@ ossl_ocspres_s_create(VALUE klass, VALUE status, VALUE basic_resp)
OCSP_BASICRESP *bs; OCSP_BASICRESP *bs;
OCSP_RESPONSE *res; OCSP_RESPONSE *res;
VALUE obj; VALUE obj;
int st = NUM2INT(status);
if(NIL_P(basic_resp)) bs = NULL; if(NIL_P(basic_resp)) bs = NULL;
else GetOCSPBasicRes(basic_resp, bs); /* NO NEED TO DUP */ else GetOCSPBasicRes(basic_resp, bs); /* NO NEED TO DUP */
if(!(res = OCSP_response_create(NUM2INT(status), bs))) if(!(res = OCSP_response_create(st, bs)))
ossl_raise(eOCSPError, NULL); ossl_raise(eOCSPError, NULL);
WrapOCSPRes(klass, obj, res); WrapOCSPRes(klass, obj, res);
@ -426,12 +428,14 @@ ossl_ocspbres_add_nonce(int argc, VALUE *argv, VALUE self)
VALUE val; VALUE val;
int ret; int ret;
GetOCSPBasicRes(self, bs);
rb_scan_args(argc, argv, "01", &val); rb_scan_args(argc, argv, "01", &val);
if(NIL_P(val)) if(NIL_P(val)) {
GetOCSPBasicRes(self, bs);
ret = OCSP_basic_add1_nonce(bs, NULL, -1); ret = OCSP_basic_add1_nonce(bs, NULL, -1);
}
else{ else{
StringValue(val); StringValue(val);
GetOCSPBasicRes(self, bs);
ret = OCSP_basic_add1_nonce(bs, RSTRING(val)->ptr, RSTRING(val)->len); ret = OCSP_basic_add1_nonce(bs, RSTRING(val)->ptr, RSTRING(val)->len);
} }
if(!ret) ossl_raise(eOCSPError, NULL); if(!ret) ossl_raise(eOCSPError, NULL);
@ -452,8 +456,6 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
int error, i, rstatus = 0; int error, i, rstatus = 0;
VALUE tmp; VALUE tmp;
GetOCSPBasicRes(self, bs);
SafeGetOCSPCertId(cid, id);
st = NUM2INT(status); st = NUM2INT(status);
rsn = NIL_P(status) ? 0 : NUM2INT(reason); rsn = NIL_P(status) ? 0 : NUM2INT(reason);
if(!NIL_P(ext)){ if(!NIL_P(ext)){
@ -477,6 +479,8 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
if(rstatus) goto err; if(rstatus) goto err;
nxt = X509_gmtime_adj(NULL, NUM2INT(tmp)); nxt = X509_gmtime_adj(NULL, NUM2INT(tmp));
GetOCSPBasicRes(self, bs);
SafeGetOCSPCertId(cid, id);
if(!(single = OCSP_basic_add1_status(bs, id, st, rsn, rev, ths, nxt))){ if(!(single = OCSP_basic_add1_status(bs, id, st, rsn, rev, ths, nxt))){
error = 1; error = 1;
goto err; goto err;
@ -564,7 +568,6 @@ ossl_ocspbres_sign(int argc, VALUE *argv, VALUE self)
int ret; int ret;
rb_scan_args(argc, argv, "22", &signer_cert, &signer_key, &certs, &flags); rb_scan_args(argc, argv, "22", &signer_cert, &signer_key, &certs, &flags);
GetOCSPBasicRes(self, bs);
signer = GetX509CertPtr(signer_cert); signer = GetX509CertPtr(signer_cert);
key = GetPrivPKeyPtr(signer_key); key = GetPrivPKeyPtr(signer_key);
flg = NIL_P(flags) ? 0 : NUM2INT(flags); flg = NIL_P(flags) ? 0 : NUM2INT(flags);
@ -575,6 +578,7 @@ ossl_ocspbres_sign(int argc, VALUE *argv, VALUE self)
else{ else{
x509s = ossl_x509_ary2sk(certs); x509s = ossl_x509_ary2sk(certs);
} }
GetOCSPBasicRes(self, bs);
ret = OCSP_basic_sign(bs, signer, key, EVP_sha1(), x509s, flg); ret = OCSP_basic_sign(bs, signer, key, EVP_sha1(), x509s, flg);
sk_X509_pop_free(x509s, X509_free); sk_X509_pop_free(x509s, X509_free);
if(!ret) ossl_raise(eOCSPError, NULL); if(!ret) ossl_raise(eOCSPError, NULL);
@ -592,10 +596,10 @@ ossl_ocspbres_verify(int argc, VALUE *argv, VALUE self)
int flg, result; int flg, result;
rb_scan_args(argc, argv, "21", &certs, &store, &flags); rb_scan_args(argc, argv, "21", &certs, &store, &flags);
GetOCSPBasicRes(self, bs);
x509st = GetX509StorePtr(store); x509st = GetX509StorePtr(store);
flg = NIL_P(flags) ? 0 : INT2NUM(flags); flg = NIL_P(flags) ? 0 : INT2NUM(flags);
x509s = ossl_x509_ary2sk(certs); x509s = ossl_x509_ary2sk(certs);
GetOCSPBasicRes(self, bs);
result = OCSP_basic_verify(bs, x509s, x509st, flg); result = OCSP_basic_verify(bs, x509s, x509st, flg);
sk_X509_pop_free(x509s, X509_free); sk_X509_pop_free(x509s, X509_free);
if(!result) rb_warn("%s", ERR_error_string(ERR_peek_error(), NULL)); if(!result) rb_warn("%s", ERR_error_string(ERR_peek_error(), NULL));
@ -625,11 +629,11 @@ ossl_ocspcid_initialize(VALUE self, VALUE subject, VALUE issuer)
OCSP_CERTID *id, *newid; OCSP_CERTID *id, *newid;
X509 *x509s, *x509i; X509 *x509s, *x509i;
GetOCSPCertId(self, id);
x509s = GetX509CertPtr(subject); /* NO NEED TO DUP */ x509s = GetX509CertPtr(subject); /* NO NEED TO DUP */
x509i = GetX509CertPtr(issuer); /* NO NEED TO DUP */ x509i = GetX509CertPtr(issuer); /* NO NEED TO DUP */
if(!(newid = OCSP_cert_to_id(NULL, x509s, x509i))) if(!(newid = OCSP_cert_to_id(NULL, x509s, x509i)))
ossl_raise(eOCSPError, NULL); ossl_raise(eOCSPError, NULL);
GetOCSPCertId(self, id);
OCSP_CERTID_free(id); OCSP_CERTID_free(id);
RDATA(self)->data = newid; RDATA(self)->data = newid;

Просмотреть файл

@ -122,9 +122,9 @@ ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
int flg; int flg;
rb_scan_args(argc, argv, "12", &pkcs7, &data, &flags); rb_scan_args(argc, argv, "12", &pkcs7, &data, &flags);
SafeGetPKCS7(pkcs7, p7);
flg = NIL_P(flags) ? 0 : NUM2INT(flags); flg = NIL_P(flags) ? 0 : NUM2INT(flags);
if(NIL_P(data)) data = ossl_pkcs7_get_data(pkcs7); if(NIL_P(data)) data = ossl_pkcs7_get_data(pkcs7);
SafeGetPKCS7(pkcs7, p7);
if(!NIL_P(data) && PKCS7_is_detached(p7)) if(!NIL_P(data) && PKCS7_is_detached(p7))
flg |= PKCS7_DETACHED; flg |= PKCS7_DETACHED;
in = NIL_P(data) ? NULL : ossl_obj2bio(data); in = NIL_P(data) ? NULL : ossl_obj2bio(data);
@ -400,8 +400,8 @@ ossl_pkcs7_add_signer(VALUE self, VALUE signer)
PKCS7 *pkcs7; PKCS7 *pkcs7;
PKCS7_SIGNER_INFO *p7si; PKCS7_SIGNER_INFO *p7si;
GetPKCS7(self, pkcs7);
p7si = DupPKCS7SignerPtr(signer); /* NEED TO DUP */ p7si = DupPKCS7SignerPtr(signer); /* NEED TO DUP */
GetPKCS7(self, pkcs7);
if (!PKCS7_add_signer(pkcs7, p7si)) { if (!PKCS7_add_signer(pkcs7, p7si)) {
PKCS7_SIGNER_INFO_free(p7si); PKCS7_SIGNER_INFO_free(p7si);
ossl_raise(ePKCS7Error, "Could not add signer."); ossl_raise(ePKCS7Error, "Could not add signer.");
@ -447,7 +447,6 @@ ossl_pkcs7_add_recipient(VALUE self, VALUE cert)
PKCS7_RECIP_INFO *ri; PKCS7_RECIP_INFO *ri;
X509 *x509; X509 *x509;
GetPKCS7(self, pkcs7);
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */ x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
if (!(ri = PKCS7_RECIP_INFO_new())) { if (!(ri = PKCS7_RECIP_INFO_new())) {
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
@ -456,6 +455,7 @@ ossl_pkcs7_add_recipient(VALUE self, VALUE cert)
PKCS7_RECIP_INFO_free(ri); PKCS7_RECIP_INFO_free(ri);
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
} }
GetPKCS7(self, pkcs7);
if (!PKCS7_add_recipient_info(pkcs7, ri)) { if (!PKCS7_add_recipient_info(pkcs7, ri)) {
PKCS7_RECIP_INFO_free(ri); PKCS7_RECIP_INFO_free(ri);
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
@ -582,9 +582,7 @@ ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
VALUE data; VALUE data;
const char *msg; const char *msg;
GetPKCS7(self, p7);
rb_scan_args(argc, argv, "22", &certs, &store, &indata, &flags); rb_scan_args(argc, argv, "22", &certs, &store, &indata, &flags);
x509st = GetX509StorePtr(store);
flg = NIL_P(flags) ? 0 : NUM2INT(flags); flg = NIL_P(flags) ? 0 : NUM2INT(flags);
if(NIL_P(indata)) indata = ossl_pkcs7_get_data(self); if(NIL_P(indata)) indata = ossl_pkcs7_get_data(self);
in = NIL_P(indata) ? NULL : ossl_obj2bio(indata); in = NIL_P(indata) ? NULL : ossl_obj2bio(indata);
@ -596,6 +594,8 @@ ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
rb_jump_tag(status); rb_jump_tag(status);
} }
} }
x509st = GetX509StorePtr(store);
GetPKCS7(self, p7);
if(!(out = BIO_new(BIO_s_mem()))){ if(!(out = BIO_new(BIO_s_mem()))){
BIO_free(in); BIO_free(in);
sk_X509_pop_free(x509s, X509_free); sk_X509_pop_free(x509s, X509_free);
@ -624,10 +624,10 @@ ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
VALUE str; VALUE str;
rb_scan_args(argc, argv, "21", &pkey, &cert, &flags); rb_scan_args(argc, argv, "21", &pkey, &cert, &flags);
GetPKCS7(self, p7);
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */ key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */ x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
flg = NIL_P(flags) ? 0 : NUM2INT(flags); flg = NIL_P(flags) ? 0 : NUM2INT(flags);
GetPKCS7(self, p7);
if(!(out = BIO_new(BIO_s_mem()))) if(!(out = BIO_new(BIO_s_mem())))
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
if(!PKCS7_decrypt(p7, key, x509, out, flg)){ if(!PKCS7_decrypt(p7, key, x509, out, flg)){
@ -647,13 +647,12 @@ ossl_pkcs7_add_data(VALUE self, VALUE data)
char buf[4096]; char buf[4096];
int len; int len;
in = out = NULL; in = ossl_obj2bio(data);
GetPKCS7(self, pkcs7); GetPKCS7(self, pkcs7);
if(PKCS7_type_is_signed(pkcs7)){ if(PKCS7_type_is_signed(pkcs7)){
if(!PKCS7_content_new(pkcs7, NID_pkcs7_data)) if(!PKCS7_content_new(pkcs7, NID_pkcs7_data))
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
} }
in = ossl_obj2bio(data);
if(!(out = PKCS7_dataInit(pkcs7, NULL))) goto err; if(!(out = PKCS7_dataInit(pkcs7, NULL))) goto err;
for(;;){ for(;;){
if((len = BIO_read(in, buf, sizeof(buf))) <= 0) if((len = BIO_read(in, buf, sizeof(buf))) <= 0)
@ -739,10 +738,10 @@ ossl_pkcs7si_initialize(VALUE self, VALUE cert, VALUE key, VALUE digest)
X509 *x509; X509 *x509;
const EVP_MD *md; const EVP_MD *md;
GetPKCS7si(self, p7si);
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */ x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
md = GetDigestPtr(digest); md = GetDigestPtr(digest);
GetPKCS7si(self, p7si);
if (!(PKCS7_SIGNER_INFO_set(p7si, x509, pkey, (EVP_MD*)md))) { if (!(PKCS7_SIGNER_INFO_set(p7si, x509, pkey, (EVP_MD*)md))) {
ossl_raise(ePKCS7Error, NULL); ossl_raise(ePKCS7Error, NULL);
} }

Просмотреть файл

@ -119,8 +119,6 @@ ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
int i; int i;
char *s; char *s;
Data_Get_Struct(self, SSL_CTX, ctx);
for(i = 0; i < numberof(ossl_sslctx_attrs); i++){ for(i = 0; i < numberof(ossl_sslctx_attrs); i++){
char buf[32]; char buf[32];
snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]); snprintf(buf, sizeof(buf), "@%s", ossl_sslctx_attrs[i]);
@ -142,6 +140,7 @@ ossl_sslctx_initialize(int argc, VALUE *argv, VALUE self)
if (!method) { if (!method) {
ossl_raise(rb_eArgError, "unknown SSL method `%s'.", s); ossl_raise(rb_eArgError, "unknown SSL method `%s'.", s);
} }
Data_Get_Struct(self, SSL_CTX, ctx);
if (SSL_CTX_set_ssl_version(ctx, method) != 1) { if (SSL_CTX_set_ssl_version(ctx, method) != 1) {
ossl_raise(eSSLError, "SSL_CTX_set_ssl_version:"); ossl_raise(eSSLError, "SSL_CTX_set_ssl_version:");
} }
@ -325,12 +324,6 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
int i; int i;
rb_check_frozen(self); rb_check_frozen(self);
Data_Get_Struct(self, SSL_CTX, ctx);
if(!ctx){
ossl_raise(eSSLError, "SSL_CTX is not initialized.");
return Qnil;
}
if (TYPE(v) == T_ARRAY) { if (TYPE(v) == T_ARRAY) {
str = rb_str_new2(NULL); str = rb_str_new2(NULL);
for (i = 0; i < RARRAY(v)->len; i++) { for (i = 0; i < RARRAY(v)->len; i++) {
@ -345,6 +338,11 @@ ossl_sslctx_set_ciphers(VALUE self, VALUE v)
StringValue(str); StringValue(str);
} }
Data_Get_Struct(self, SSL_CTX, ctx);
if(!ctx){
ossl_raise(eSSLError, "SSL_CTX is not initialized.");
return Qnil;
}
if (!SSL_CTX_set_cipher_list(ctx, RSTRING(str)->ptr)) { if (!SSL_CTX_set_cipher_list(ctx, RSTRING(str)->ptr)) {
ossl_raise(eSSLError, "SSL_CTX_set_ciphers:"); ossl_raise(eSSLError, "SSL_CTX_set_ciphers:");
} }
@ -491,8 +489,6 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
VALUE len, str; VALUE len, str;
OpenFile *fptr; OpenFile *fptr;
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
rb_scan_args(argc, argv, "11", &len, &str); rb_scan_args(argc, argv, "11", &len, &str);
ilen = NUM2INT(len); ilen = NUM2INT(len);
if(NIL_P(str)) str = rb_str_new(0, ilen); if(NIL_P(str)) str = rb_str_new(0, ilen);
@ -503,6 +499,8 @@ ossl_ssl_read(int argc, VALUE *argv, VALUE self)
} }
if(ilen == 0) return str; if(ilen == 0) return str;
Data_Get_Struct(self, SSL, ssl);
GetOpenFile(ossl_ssl_get_io(self), fptr);
if (ssl) { if (ssl) {
if(SSL_pending(ssl) <= 0) if(SSL_pending(ssl) <= 0)
rb_thread_wait_fd(fptr->fd); rb_thread_wait_fd(fptr->fd);
@ -545,8 +543,8 @@ ossl_ssl_write(VALUE self, VALUE str)
SSL *ssl; SSL *ssl;
int nwrite = 0; int nwrite = 0;
Data_Get_Struct(self, SSL, ssl);
StringValue(str); StringValue(str);
Data_Get_Struct(self, SSL, ssl);
if (ssl) { if (ssl) {
for (;;){ for (;;){

Просмотреть файл

@ -115,11 +115,11 @@ ossl_x509attr_set_oid(VALUE self, VALUE oid)
ASN1_OBJECT *obj; ASN1_OBJECT *obj;
char *s; char *s;
GetX509Attr(self, attr);
s = StringValuePtr(oid); s = StringValuePtr(oid);
obj = OBJ_txt2obj(s, 0); obj = OBJ_txt2obj(s, 0);
if(!obj) obj = OBJ_txt2obj(s, 1); if(!obj) obj = OBJ_txt2obj(s, 1);
if(!obj) ossl_raise(eX509AttrError, NULL); if(!obj) ossl_raise(eX509AttrError, NULL);
GetX509Attr(self, attr);
X509_ATTRIBUTE_set1_object(attr, obj); X509_ATTRIBUTE_set1_object(attr, obj);
return oid; return oid;
@ -162,13 +162,13 @@ ossl_x509attr_set_value(VALUE self, VALUE value)
X509_ATTRIBUTE *attr; X509_ATTRIBUTE *attr;
ASN1_TYPE *a1type; ASN1_TYPE *a1type;
GetX509Attr(self, attr);
if(!(a1type = ossl_asn1_get_asn1type(value))) if(!(a1type = ossl_asn1_get_asn1type(value)))
ossl_raise(eASN1Error, "could not get ASN1_TYPE"); ossl_raise(eASN1Error, "could not get ASN1_TYPE");
if(ASN1_TYPE_get(a1type) == V_ASN1_SEQUENCE){ if(ASN1_TYPE_get(a1type) == V_ASN1_SEQUENCE){
ASN1_TYPE_free(a1type); ASN1_TYPE_free(a1type);
ossl_raise(eASN1Error, "couldn't set SEQUENCE for attribute value."); ossl_raise(eASN1Error, "couldn't set SEQUENCE for attribute value.");
} }
GetX509Attr(self, attr);
if(attr->value.set){ if(attr->value.set){
if(OSSL_X509ATTR_IS_SINGLE(attr)) ASN1_TYPE_free(attr->value.single); if(OSSL_X509ATTR_IS_SINGLE(attr)) ASN1_TYPE_free(attr->value.single);
else sk_ASN1_TYPE_free(attr->value.set); else sk_ASN1_TYPE_free(attr->value.set);

Просмотреть файл

@ -268,10 +268,10 @@ ossl_x509_set_version(VALUE self, VALUE version)
X509 *x509; X509 *x509;
long ver; long ver;
GetX509(self, x509);
if ((ver = NUM2LONG(version)) < 0) { if ((ver = NUM2LONG(version)) < 0) {
ossl_raise(eX509CertError, "version must be >= 0!"); ossl_raise(eX509CertError, "version must be >= 0!");
} }
GetX509(self, x509);
if (!X509_set_version(x509, ver)) { if (!X509_set_version(x509, ver)) {
ossl_raise(eX509CertError, NULL); ossl_raise(eX509CertError, NULL);
} }
@ -310,7 +310,6 @@ ossl_x509_get_signature_algorithm(VALUE self)
VALUE str; VALUE str;
GetX509(self, x509); GetX509(self, x509);
out = BIO_new(BIO_s_mem()); out = BIO_new(BIO_s_mem());
if (!out) ossl_raise(eX509CertError, NULL); if (!out) ossl_raise(eX509CertError, NULL);
@ -397,8 +396,8 @@ ossl_x509_set_not_before(VALUE self, VALUE time)
X509 *x509; X509 *x509;
time_t sec; time_t sec;
GetX509(self, x509);
sec = time_to_time_t(time); sec = time_to_time_t(time);
GetX509(self, x509);
if (!X509_time_adj(X509_get_notBefore(x509), 0, &sec)) { if (!X509_time_adj(X509_get_notBefore(x509), 0, &sec)) {
ossl_raise(eX509CertError, NULL); ossl_raise(eX509CertError, NULL);
} }
@ -426,8 +425,8 @@ ossl_x509_set_not_after(VALUE self, VALUE time)
X509 *x509; X509 *x509;
time_t sec; time_t sec;
GetX509(self, x509);
sec = time_to_time_t(time); sec = time_to_time_t(time);
GetX509(self, x509);
if (!X509_time_adj(X509_get_notAfter(x509), 0, &sec)) { if (!X509_time_adj(X509_get_notAfter(x509), 0, &sec)) {
ossl_raise(eX509CertError, NULL); ossl_raise(eX509CertError, NULL);
} }
@ -469,9 +468,9 @@ ossl_x509_sign(VALUE self, VALUE key, VALUE digest)
EVP_PKEY *pkey; EVP_PKEY *pkey;
const EVP_MD *md; const EVP_MD *md;
GetX509(self, x509);
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
md = GetDigestPtr(digest); md = GetDigestPtr(digest);
GetX509(self, x509);
if (!X509_sign(x509, pkey, md)) { if (!X509_sign(x509, pkey, md)) {
ossl_raise(eX509CertError, NULL); ossl_raise(eX509CertError, NULL);
} }
@ -489,8 +488,8 @@ ossl_x509_verify(VALUE self, VALUE key)
EVP_PKEY *pkey; EVP_PKEY *pkey;
int i; int i;
GetX509(self, x509);
pkey = GetPKeyPtr(key); /* NO NEED TO DUP */ pkey = GetPKeyPtr(key); /* NO NEED TO DUP */
GetX509(self, x509);
if ((i = X509_verify(x509, pkey)) < 0) { if ((i = X509_verify(x509, pkey)) < 0) {
ossl_raise(eX509CertError, NULL); ossl_raise(eX509CertError, NULL);
} }
@ -510,9 +509,9 @@ ossl_x509_check_private_key(VALUE self, VALUE key)
X509 *x509; X509 *x509;
EVP_PKEY *pkey; EVP_PKEY *pkey;
GetX509(self, x509);
/* not needed private key, but should be */ /* not needed private key, but should be */
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
GetX509(self, x509);
if (!X509_check_private_key(x509, pkey)) { if (!X509_check_private_key(x509, pkey)) {
OSSL_Warning("Check private key:%s", OSSL_ErrMsg()); OSSL_Warning("Check private key:%s", OSSL_ErrMsg());
return Qfalse; return Qfalse;
@ -556,12 +555,12 @@ ossl_x509_set_extensions(VALUE self, VALUE ary)
X509_EXTENSION *ext; X509_EXTENSION *ext;
int i; int i;
GetX509(self, x509);
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
/* All ary's members should be X509Extension */ /* All ary's members should be X509Extension */
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext); OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
} }
GetX509(self, x509);
sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free); sk_X509_EXTENSION_pop_free(x509->cert_info->extensions, X509_EXTENSION_free);
x509->cert_info->extensions = NULL; x509->cert_info->extensions = NULL;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {

Просмотреть файл

@ -146,11 +146,10 @@ ossl_x509crl_set_version(VALUE self, VALUE version)
X509_CRL *crl; X509_CRL *crl;
long ver; long ver;
GetX509CRL(self, crl);
if ((ver = NUM2LONG(version)) < 0) { if ((ver = NUM2LONG(version)) < 0) {
ossl_raise(eX509CRLError, "version must be >= 0!"); ossl_raise(eX509CRLError, "version must be >= 0!");
} }
GetX509CRL(self, crl);
if (!X509_CRL_set_version(crl, ver)) { if (!X509_CRL_set_version(crl, ver)) {
ossl_raise(eX509CRLError, NULL); ossl_raise(eX509CRLError, NULL);
} }
@ -167,7 +166,6 @@ ossl_x509crl_get_signature_algorithm(VALUE self)
VALUE str; VALUE str;
GetX509CRL(self, crl); GetX509CRL(self, crl);
if (!(out = BIO_new(BIO_s_mem()))) { if (!(out = BIO_new(BIO_s_mem()))) {
ossl_raise(eX509CRLError, NULL); ossl_raise(eX509CRLError, NULL);
} }
@ -220,8 +218,8 @@ ossl_x509crl_set_last_update(VALUE self, VALUE time)
X509_CRL *crl; X509_CRL *crl;
time_t sec; time_t sec;
GetX509CRL(self, crl);
sec = time_to_time_t(time); sec = time_to_time_t(time);
GetX509CRL(self, crl);
if (!X509_time_adj(crl->crl->lastUpdate, 0, &sec)) { if (!X509_time_adj(crl->crl->lastUpdate, 0, &sec)) {
ossl_raise(eX509CRLError, NULL); ossl_raise(eX509CRLError, NULL);
} }
@ -245,8 +243,8 @@ ossl_x509crl_set_next_update(VALUE self, VALUE time)
X509_CRL *crl; X509_CRL *crl;
time_t sec; time_t sec;
GetX509CRL(self, crl);
sec = time_to_time_t(time); sec = time_to_time_t(time);
GetX509CRL(self, crl);
/* This must be some thinko in OpenSSL */ /* This must be some thinko in OpenSSL */
if (!(crl->crl->nextUpdate = X509_time_adj(crl->crl->nextUpdate, 0, &sec))){ if (!(crl->crl->nextUpdate = X509_time_adj(crl->crl->nextUpdate, 0, &sec))){
ossl_raise(eX509CRLError, NULL); ossl_raise(eX509CRLError, NULL);
@ -287,12 +285,12 @@ ossl_x509crl_set_revoked(VALUE self, VALUE ary)
X509_REVOKED *rev; X509_REVOKED *rev;
int i; int i;
GetX509CRL(self, crl);
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Revoked */ /* All ary members should be X509 Revoked */
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev); OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Rev);
} }
GetX509CRL(self, crl);
sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free); sk_X509_REVOKED_pop_free(crl->crl->revoked, X509_REVOKED_free);
crl->crl->revoked = NULL; crl->crl->revoked = NULL;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
@ -461,12 +459,12 @@ ossl_x509crl_set_extensions(VALUE self, VALUE ary)
X509_EXTENSION *ext; X509_EXTENSION *ext;
int i; int i;
GetX509CRL(self, crl);
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
/* All ary members should be X509 Extensions */ /* All ary members should be X509 Extensions */
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext); OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
} }
GetX509CRL(self, crl);
sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free); sk_X509_EXTENSION_pop_free(crl->crl->extensions, X509_EXTENSION_free);
crl->crl->extensions = NULL; crl->crl->extensions = NULL;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {

Просмотреть файл

@ -215,7 +215,6 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
VALUE oid, value, critical, valstr, obj; VALUE oid, value, critical, valstr, obj;
int nid; int nid;
GetX509ExtFactory(self, ctx);
rb_scan_args(argc, argv, "21", &oid, &value, &critical); rb_scan_args(argc, argv, "21", &oid, &value, &critical);
StringValue(oid); StringValue(oid);
StringValue(value); StringValue(value);
@ -226,6 +225,7 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING(oid)->ptr); if(!nid) ossl_raise(eX509ExtError, "unknown OID `%s'", RSTRING(oid)->ptr);
valstr = rb_str_new2(RTEST(critical) ? "critical," : ""); valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value); rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
ext = X509V3_EXT_conf_nid(NULL, ctx, nid, RSTRING(valstr)->ptr); ext = X509V3_EXT_conf_nid(NULL, ctx, nid, RSTRING(valstr)->ptr);
if (!ext){ if (!ext){
ossl_raise(eX509ExtError, "%s = %s", ossl_raise(eX509ExtError, "%s = %s",
@ -284,11 +284,11 @@ ossl_x509ext_set_oid(VALUE self, VALUE oid)
ASN1_OBJECT *obj; ASN1_OBJECT *obj;
char *s; char *s;
GetX509Ext(self, ext);
s = StringValuePtr(oid); s = StringValuePtr(oid);
obj = OBJ_txt2obj(s, 0); obj = OBJ_txt2obj(s, 0);
if(!obj) obj = OBJ_txt2obj(s, 1); if(!obj) obj = OBJ_txt2obj(s, 1);
if(!obj) ossl_raise(eX509ExtError, NULL); if(!obj) ossl_raise(eX509ExtError, NULL);
GetX509Ext(self, ext);
X509_EXTENSION_set_object(ext, obj); X509_EXTENSION_set_object(ext, obj);
return oid; return oid;
@ -301,7 +301,6 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
ASN1_OCTET_STRING *asn1s; ASN1_OCTET_STRING *asn1s;
char *s; char *s;
GetX509Ext(self, ext);
data = ossl_to_der_if_possible(data); data = ossl_to_der_if_possible(data);
StringValue(data); StringValue(data);
if(!(s = OPENSSL_malloc(RSTRING(data)->len))) if(!(s = OPENSSL_malloc(RSTRING(data)->len)))
@ -316,6 +315,7 @@ ossl_x509ext_set_value(VALUE self, VALUE data)
ASN1_OCTET_STRING_free(asn1s); ASN1_OCTET_STRING_free(asn1s);
ossl_raise(eX509ExtError, NULL); ossl_raise(eX509ExtError, NULL);
} }
GetX509Ext(self, ext);
X509_EXTENSION_set_data(ext, asn1s); X509_EXTENSION_set_data(ext, asn1s);
return data; return data;
@ -376,6 +376,7 @@ static VALUE
ossl_x509ext_get_critical(VALUE obj) ossl_x509ext_get_critical(VALUE obj)
{ {
X509_EXTENSION *ext; X509_EXTENSION *ext;
GetX509Ext(obj, ext); GetX509Ext(obj, ext);
return X509_EXTENSION_get_critical(ext) ? Qtrue : Qfalse; return X509_EXTENSION_get_critical(ext) ? Qtrue : Qfalse;
} }

Просмотреть файл

@ -119,19 +119,22 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
if (rb_scan_args(argc, argv, "02", &arg, &template) == 0) { if (rb_scan_args(argc, argv, "02", &arg, &template) == 0) {
return self; return self;
} }
else if (rb_obj_is_kind_of(arg, rb_cArray) == Qtrue){ else {
VALUE args; VALUE tmp = rb_check_array_type(arg);
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE; if (!NIL_P(tmp)) {
args = rb_ary_new3(2, self, template); VALUE args;
rb_iterate(rb_each, arg, ossl_x509name_init_i, args); if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
} args = rb_ary_new3(2, self, template);
else{ rb_iterate(rb_each, tmp, ossl_x509name_init_i, args);
unsigned char *p; }
VALUE str = ossl_to_der_if_possible(arg); else{
StringValue(str); unsigned char *p;
p = RSTRING(str)->ptr; VALUE str = ossl_to_der_if_possible(arg);
if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING(str)->len)){ StringValue(str);
ossl_raise(eX509NameError, NULL); p = RSTRING(str)->ptr;
if(!d2i_X509_NAME((X509_NAME**)&DATA_PTR(self), &p, RSTRING(str)->len)){
ossl_raise(eX509NameError, NULL);
}
} }
} }
@ -180,13 +183,13 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
BIO *out; BIO *out;
unsigned long iflag; unsigned long iflag;
GetX509Name(self, name);
rb_scan_args(argc, argv, "01", &flag); rb_scan_args(argc, argv, "01", &flag);
if (NIL_P(flag)) if (NIL_P(flag))
return ossl_x509name_to_s_old(self); return ossl_x509name_to_s_old(self);
else iflag = NUM2ULONG(flag); else iflag = NUM2ULONG(flag);
if (!(out = BIO_new(BIO_s_mem()))) if (!(out = BIO_new(BIO_s_mem())))
rb_raise(eX509NameError, NULL); rb_raise(eX509NameError, NULL);
GetX509Name(self, name);
if (!X509_NAME_print_ex(out, name, 0, iflag)){ if (!X509_NAME_print_ex(out, name, 0, iflag)){
BIO_free(out); BIO_free(out);
rb_raise(eX509NameError, NULL); rb_raise(eX509NameError, NULL);

Просмотреть файл

@ -240,10 +240,10 @@ ossl_x509req_set_version(VALUE self, VALUE version)
X509_REQ *req; X509_REQ *req;
long ver; long ver;
GetX509Req(self, req);
if ((ver = FIX2LONG(version)) < 0) { if ((ver = FIX2LONG(version)) < 0) {
ossl_raise(eX509ReqError, "version must be >= 0!"); ossl_raise(eX509ReqError, "version must be >= 0!");
} }
GetX509Req(self, req);
if (!X509_REQ_set_version(req, ver)) { if (!X509_REQ_set_version(req, ver)) {
ossl_raise(eX509ReqError, NULL); ossl_raise(eX509ReqError, NULL);
} }
@ -400,13 +400,13 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
X509_REQ *req; X509_REQ *req;
X509_ATTRIBUTE *attr; X509_ATTRIBUTE *attr;
int i; int i;
VALUE item; VALUE tmp, item;
GetX509Req(self, req);
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
for (i=0;i<RARRAY(ary)->len; i++) { for (i=0;i<RARRAY(ary)->len; i++) {
OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Attr); OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Attr);
} }
GetX509Req(self, req);
sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free); sk_X509_ATTRIBUTE_pop_free(req->req_info->attributes, X509_ATTRIBUTE_free);
req->req_info->attributes = NULL; req->req_info->attributes = NULL;
for (i=0;i<RARRAY(ary)->len; i++) { for (i=0;i<RARRAY(ary)->len; i++) {

Просмотреть файл

@ -129,8 +129,8 @@ ossl_x509revoked_set_time(VALUE self, VALUE time)
X509_REVOKED *rev; X509_REVOKED *rev;
time_t sec; time_t sec;
GetX509Rev(self, rev);
sec = time_to_time_t(time); sec = time_to_time_t(time);
GetX509Rev(self, rev);
if (!X509_time_adj(rev->revocationDate, 0, &sec)) { if (!X509_time_adj(rev->revocationDate, 0, &sec)) {
ossl_raise(eX509RevError, NULL); ossl_raise(eX509RevError, NULL);
} }
@ -174,11 +174,11 @@ ossl_x509revoked_set_extensions(VALUE self, VALUE ary)
int i; int i;
VALUE item; VALUE item;
GetX509Rev(self, rev);
Check_Type(ary, T_ARRAY); Check_Type(ary, T_ARRAY);
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext); OSSL_Check_Kind(RARRAY(ary)->ptr[i], cX509Ext);
} }
GetX509Rev(self, rev);
sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free); sk_X509_EXTENSION_pop_free(rev->extensions, X509_EXTENSION_free);
rev->extensions = NULL; rev->extensions = NULL;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {

Просмотреть файл

@ -146,9 +146,10 @@ ossl_x509store_set_flags(VALUE self, VALUE flags)
{ {
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L) #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
X509_STORE *store; X509_STORE *store;
long f = NUM2LONG(flags);
GetX509Store(self, store); GetX509Store(self, store);
X509_STORE_set_flags(store, NUM2LONG(flags)); X509_STORE_set_flags(store, f);
#else #else
rb_iv_set(self, "@flags", flags); rb_iv_set(self, "@flags", flags);
#endif #endif
@ -161,9 +162,10 @@ ossl_x509store_set_purpose(VALUE self, VALUE purpose)
{ {
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L) #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
X509_STORE *store; X509_STORE *store;
long p = NUM2LONG(purpose);
GetX509Store(self, store); GetX509Store(self, store);
X509_STORE_set_purpose(store, NUM2LONG(purpose)); X509_STORE_set_purpose(store, p);
#else #else
rb_iv_set(self, "@purpose", purpose); rb_iv_set(self, "@purpose", purpose);
#endif #endif
@ -176,9 +178,10 @@ ossl_x509store_set_trust(VALUE self, VALUE trust)
{ {
#if (OPENSSL_VERSION_NUMBER >= 0x00907000L) #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
X509_STORE *store; X509_STORE *store;
long t = NUM2LONG(trust);
GetX509Store(self, store); GetX509Store(self, store);
X509_STORE_set_trust(store, NUM2LONG(trust)); X509_STORE_set_trust(store, t);
#else #else
rb_iv_set(self, "@trust", trust); rb_iv_set(self, "@trust", trust);
#endif #endif
@ -350,8 +353,8 @@ ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
X509 *x509 = NULL; X509 *x509 = NULL;
STACK_OF(X509) *x509s = NULL; STACK_OF(X509) *x509s = NULL;
GetX509StCtx(self, ctx);
rb_scan_args(argc, argv, "12", &store, &cert, &chain); rb_scan_args(argc, argv, "12", &store, &cert, &chain);
GetX509StCtx(self, ctx);
SafeGetX509Store(store, x509st); SafeGetX509Store(store, x509st);
if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */ if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */
if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain); if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
@ -496,9 +499,10 @@ static VALUE
ossl_x509stctx_set_flags(VALUE self, VALUE flags) ossl_x509stctx_set_flags(VALUE self, VALUE flags)
{ {
X509_STORE_CTX *store; X509_STORE_CTX *store;
long f = NUM2LONG(flags);
GetX509StCtx(self, store); GetX509StCtx(self, store);
X509_STORE_CTX_set_flags(store, NUM2LONG(flags)); X509_STORE_CTX_set_flags(store, f);
return flags; return flags;
} }
@ -507,9 +511,10 @@ static VALUE
ossl_x509stctx_set_purpose(VALUE self, VALUE purpose) ossl_x509stctx_set_purpose(VALUE self, VALUE purpose)
{ {
X509_STORE_CTX *store; X509_STORE_CTX *store;
long p = NUM2LONG(purpose);
GetX509StCtx(self, store); GetX509StCtx(self, store);
X509_STORE_CTX_set_purpose(store, NUM2LONG(purpose)); X509_STORE_CTX_set_purpose(store, p);
return purpose; return purpose;
} }
@ -518,9 +523,10 @@ static VALUE
ossl_x509stctx_set_trust(VALUE self, VALUE trust) ossl_x509stctx_set_trust(VALUE self, VALUE trust)
{ {
X509_STORE_CTX *store; X509_STORE_CTX *store;
long t = NUM2LONG(trust);
GetX509StCtx(self, store); GetX509StCtx(self, store);
X509_STORE_CTX_set_trust(store, NUM2LONG(trust)); X509_STORE_CTX_set_trust(store, t);
return trust; return trust;
} }
@ -530,9 +536,16 @@ ossl_x509stctx_set_time(VALUE self, VALUE time)
{ {
X509_STORE_CTX *store; X509_STORE_CTX *store;
GetX509StCtx(self, store); if(NIL_P(time)) {
if(NIL_P(time)) store->flags &= ~X509_V_FLAG_USE_CHECK_TIME; GetX509StCtx(self, store);
else X509_STORE_CTX_set_time(store, 0, NUM2LONG(rb_Integer(time))); store->flags &= ~X509_V_FLAG_USE_CHECK_TIME;
}
else {
long t = NUM2LONG(rb_Integer(time));
GetX509StCtx(self, store);
X509_STORE_CTX_set_time(store, 0, t);
}
return time; return time;
} }

Просмотреть файл

@ -155,6 +155,9 @@ class CGI
# #
class Session class Session
#:nodoc:
class NoSession < RuntimeError; end
# The id of this session. # The id of this session.
attr_reader :session_id, :new_session attr_reader :session_id, :new_session
@ -243,35 +246,43 @@ class CGI
def initialize(request, option={}) def initialize(request, option={})
@new_session = false @new_session = false
session_key = option['session_key'] || '_session_id' session_key = option['session_key'] || '_session_id'
id = option['session_id'] session_id = option['session_id']
unless id unless session_id
if option['new_session'] if option['new_session']
id = create_new_id session_id = create_new_id
end end
end end
unless id unless session_id
if request.key?(session_key) if request.key?(session_key)
id = request[session_key] session_id = request[session_key]
id = id.read if id.respond_to?(:read) session_id = session_id.read if session_id.respond_to?(:read)
end end
unless id unless session_id
id, = request.cookies[session_key] session_id, = request.cookies[session_key]
end end
unless id unless session_id
if option.key?('new_session') and not option['new_session'] if option.key?('new_session') and not option['new_session']
raise ArgumentError, "session_key `%s' should be supplied"%session_key raise ArgumentError, "session_key `%s' should be supplied"%session_key
end end
id = create_new_id session_id = create_new_id
end end
end end
@session_id = id @session_id = session_id
dbman = option['database_manager'] || FileStore dbman = option['database_manager'] || FileStore
@dbman = dbman::new(self, option) begin
@dbman = dbman::new(self, option)
rescue NoSession
if option.key?('new_session') and not option['new_session']
raise ArgumentError, "invalid session_id `%s'"%session_id
end
session_id = @session_id = create_new_id
retry
end
request.instance_eval do request.instance_eval do
@output_hidden = {session_key => id} @output_hidden = {session_key => session_id}
@output_cookies = [ @output_cookies = [
Cookie::new("name" => session_key, Cookie::new("name" => session_key,
"value" => id, "value" => session_id,
"expires" => option['session_expires'], "expires" => option['session_expires'],
"domain" => option['session_domain'], "domain" => option['session_domain'],
"secure" => option['session_secure'], "secure" => option['session_secure'],
@ -371,7 +382,7 @@ class CGI
@path = dir+"/"+prefix+md5+suffix @path = dir+"/"+prefix+md5+suffix
unless File::exist? @path unless File::exist? @path
unless session.new_session unless session.new_session
raise RuntimeError, "uninitialized session" raise CGI::Session::NoSession, "uninitialized session"
end end
@hash = {} @hash = {}
end end
@ -441,7 +452,7 @@ class CGI
@session_id = session.session_id @session_id = session.session_id
unless GLOBAL_HASH_TABLE.key?(@session_id) unless GLOBAL_HASH_TABLE.key?(@session_id)
unless session.new_session unless session.new_session
raise RuntimeError, "uninitialized session" raise CGI::Session::NoSession, "uninitialized session"
end end
GLOBAL_HASH_TABLE[@session_id] = {} GLOBAL_HASH_TABLE[@session_id] = {}
end end

Просмотреть файл

@ -63,7 +63,7 @@ class CGI
path.untaint path.untaint
unless File::exist?(path) unless File::exist?(path)
unless session.new_session unless session.new_session
raise RuntimeError, "uninitialized session" raise CGI::Session::NoSession, "uninitialized session"
end end
@hash = {} @hash = {}
end end

Просмотреть файл

@ -193,7 +193,7 @@ class Set
# Adds the given object to the set and returns self. Use +merge+ to # Adds the given object to the set and returns self. Use +merge+ to
# add several elements at once. # add several elements at once.
def add(o) def add(o)
@hash[o] = true @hash[o] = o
self self
end end
alias << add alias << add
@ -313,7 +313,7 @@ class Set
set.is_a?(Set) && size == set.size or return false set.is_a?(Set) && size == set.size or return false
set.all? { |o| include?(o) } set.all? { |o| @hash.value?(o) }
end end
def hash # :nodoc: def hash # :nodoc:
@ -466,7 +466,7 @@ class SortedSet < Set
def add(o) def add(o)
@keys = nil @keys = nil
@hash[o] = true @hash[o] = o
self self
end end
alias << add alias << add
@ -551,7 +551,7 @@ end
# if @proc.arity == 2 # if @proc.arity == 2
# instance_eval %{ # instance_eval %{
# def add(o) # def add(o)
# @hash[o] = true if @proc.call(self, o) # @hash[o] = o if @proc.call(self, o)
# self # self
# end # end
# alias << add # alias << add
@ -560,7 +560,7 @@ end
# if include?(o) || !@proc.call(self, o) # if include?(o) || !@proc.call(self, o)
# nil # nil
# else # else
# @hash[o] = true # @hash[o] = o
# self # self
# end # end
# end # end
@ -583,7 +583,7 @@ end
# else # else
# instance_eval %{ # instance_eval %{
# def add(o) # def add(o)
# @hash[o] = true if @proc.call(o) # @hash[o] = o if @proc.call(o)
# self # self
# end # end
# alias << add # alias << add
@ -592,7 +592,7 @@ end
# if include?(o) || !@proc.call(o) # if include?(o) || !@proc.call(o)
# nil # nil
# else # else
# @hash[o] = true # @hash[o] = o
# self # self
# end # end
# end # end

8
utf8.c
Просмотреть файл

@ -226,9 +226,9 @@ utf8_mbc_to_normalize(OnigAmbigType flag, UChar** pp, UChar* end, UChar* lower)
if (*p == 195) { /* 195 == '\303' */ if (*p == 195) { /* 195 == '\303' */
int c = *(p + 1); int c = *(p + 1);
if (c >= 128) { if (c >= 128) {
if (c <= '\236' && /* upper */ if (c <= (unsigned char)'\236' && /* upper */
(flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0) { (flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0) {
if (c != '\227') { if (c != (unsigned char)'\227') {
*lower++ = *p; *lower++ = *p;
*lower = (UChar )(c + 32); *lower = (UChar )(c + 32);
(*pp) += 2; (*pp) += 2;
@ -286,11 +286,11 @@ utf8_is_mbc_ambiguous(OnigAmbigType flag, UChar** pp, UChar* end)
int c = *(p + 1); int c = *(p + 1);
if (c >= 128) { if (c >= 128) {
if ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0) { if ((flag & ONIGENC_AMBIGUOUS_MATCH_NONASCII_CASE) != 0) {
if (c <= '\236') { /* upper */ if (c <= (unsigned char)'\236') { /* upper */
if (c == '\227') return FALSE; if (c == '\227') return FALSE;
return TRUE; return TRUE;
} }
else if (c >= '\240' && c <= '\276') { /* lower */ else if (c >= (unsigned char)'\240' && c <= (unsigned char)'\276') { /* lower */
if (c == '\267') return FALSE; if (c == '\267') return FALSE;
return TRUE; return TRUE;
} }