Revision: 4510 http://trac.macosforge.org/projects/ruby/changeset/4510 Author: lsansonetti@apple.com Date: 2010-09-13 14:18:42 -0700 (Mon, 13 Sep 2010) Log Message: ----------- more openssl fixes Modified Paths: -------------- MacRuby/trunk/ext/openssl/ossl.h MacRuby/trunk/ext/openssl/ossl_asn1.c MacRuby/trunk/ext/openssl/ossl_ocsp.c MacRuby/trunk/ext/openssl/ossl_pkcs12.c MacRuby/trunk/ext/openssl/ossl_pkcs7.c MacRuby/trunk/ext/openssl/ossl_pkey_dh.c MacRuby/trunk/ext/openssl/ossl_pkey_dsa.c MacRuby/trunk/ext/openssl/ossl_pkey_ec.c MacRuby/trunk/ext/openssl/ossl_x509attr.c MacRuby/trunk/ext/openssl/ossl_x509cert.c MacRuby/trunk/ext/openssl/ossl_x509req.c Modified: MacRuby/trunk/ext/openssl/ossl.h =================================================================== --- MacRuby/trunk/ext/openssl/ossl.h 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl.h 2010-09-13 21:18:42 UTC (rev 4510) @@ -119,10 +119,10 @@ VALUE ossl_buf2str(char *buf, int len); #define ossl_str_adjust(str, p) \ do{\ - int len = RSTRING_LEN(str);\ - int newlen = (p) - (unsigned char*)RSTRING_PTR(str);\ + long len = rb_bstr_length(str);\ + long newlen = (p) - (unsigned char*)rb_bstr_bytes(str);\ assert(newlen <= len);\ - rb_str_set_len(str, newlen);\ + rb_bstr_set_length(str, newlen);\ }while(0) /* Modified: MacRuby/trunk/ext/openssl/ossl_asn1.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_asn1.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_asn1.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -696,8 +696,9 @@ tag_class = ossl_asn1_tag_class(self); if((length = ASN1_object_size(1, RSTRING_LEN(value), tag)) <= 0) ossl_raise(eASN1Error, NULL); - der = rb_str_new(0, length); - p = (unsigned char *)RSTRING_PTR(der); + der = rb_bstr_new(); + rb_bstr_resize(der, length); + p = (unsigned char *)rb_bstr_bytes(der); ASN1_put_object(&p, is_cons, RSTRING_LEN(value), tag, tag_class); memcpy(p, RSTRING_PTR(value), RSTRING_LEN(value)); p += RSTRING_LEN(value); Modified: MacRuby/trunk/ext/openssl/ossl_ocsp.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_ocsp.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_ocsp.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -266,8 +266,9 @@ GetOCSPReq(self, req); if((len = i2d_OCSP_REQUEST(req, NULL)) <= 0) ossl_raise(eOCSPError, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_OCSP_REQUEST(req, &p) <= 0) ossl_raise(eOCSPError, NULL); ossl_str_adjust(str, p); @@ -380,8 +381,9 @@ GetOCSPRes(self, res); if((len = i2d_OCSP_RESPONSE(res, NULL)) <= 0) ossl_raise(eOCSPError, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_OCSP_RESPONSE(res, &p) <= 0) ossl_raise(eOCSPError, NULL); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_pkcs12.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_pkcs12.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_pkcs12.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -182,8 +182,9 @@ GetPKCS12(self, p12); if((len = i2d_PKCS12(p12, NULL)) <= 0) ossl_raise(ePKCS12Error, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_PKCS12(p12, &p) <= 0) ossl_raise(ePKCS12Error, NULL); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_pkcs7.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_pkcs7.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_pkcs7.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -779,8 +779,9 @@ GetPKCS7(self, pkcs7); if((len = i2d_PKCS7(pkcs7, NULL)) <= 0) ossl_raise(ePKCS7Error, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_PKCS7(pkcs7, &p) <= 0) ossl_raise(ePKCS7Error, NULL); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_pkey_dh.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_pkey_dh.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_pkey_dh.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -253,8 +253,9 @@ GetPKeyDH(self, pkey); if((len = i2d_DHparams(pkey->pkey.dh, NULL)) <= 0) ossl_raise(eDHError, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_DHparams(pkey->pkey.dh, &p) < 0) ossl_raise(eDHError, NULL); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_pkey_dsa.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_pkey_dsa.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_pkey_dsa.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -288,8 +288,9 @@ i2d_func = i2d_DSA_PUBKEY; if((len = i2d_func(pkey->pkey.dsa, NULL)) <= 0) ossl_raise(eDSAError, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if(i2d_func(pkey->pkey.dsa, &p) < 0) ossl_raise(eDSAError, NULL); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_pkey_ec.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_pkey_ec.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_pkey_ec.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -672,8 +672,9 @@ if (EC_KEY_get0_private_key(ec) == NULL) ossl_raise(eECError, "Private EC key needed!"); - str = rb_str_new(0, ECDSA_size(ec) + 16); - if (ECDSA_sign(0, (unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data), (unsigned char *) RSTRING_PTR(str), &buf_len, ec) != 1) + str = rb_bstr_new(); + rb_bstr_resize(str, ECDSA_size(ec) + 16); + if (ECDSA_sign(0, (const unsigned char *) RSTRING_PTR(data), RSTRING_LEN(data), (unsigned char *) rb_bstr_bytes(str), &buf_len, ec) != 1) ossl_raise(eECError, "ECDSA_sign"); rb_str_resize(str, buf_len); Modified: MacRuby/trunk/ext/openssl/ossl_x509attr.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_x509attr.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_x509attr.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -212,16 +212,18 @@ if(attr->value.ptr == NULL) return Qnil; if(OSSL_X509ATTR_IS_SINGLE(attr)){ length = i2d_ASN1_TYPE(attr->value.single, NULL); - str = rb_str_new(0, length); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, length); + p = (unsigned char *)rb_bstr_bytes(str); i2d_ASN1_TYPE(attr->value.single, &p); ossl_str_adjust(str, p); } else{ length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL, i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0); - str = rb_str_new(0, length); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, length); + p = (unsigned char *)rb_bstr_bytes(str); i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p, i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0); ossl_str_adjust(str, p); Modified: MacRuby/trunk/ext/openssl/ossl_x509cert.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_x509cert.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_x509cert.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -191,8 +191,8 @@ GetX509(self, x509); if ((len = i2d_X509(x509, NULL)) <= 0) ossl_raise(eX509CertError, NULL); - str = rb_bstr_new_with_data(0, len); - rb_bstr_set_length(str, len); + str = rb_bstr_new(); + rb_bstr_resize(str, len); p = (unsigned char *)rb_bstr_bytes(str); if (i2d_X509(x509, &p) <= 0) ossl_raise(eX509CertError, NULL); Modified: MacRuby/trunk/ext/openssl/ossl_x509req.c =================================================================== --- MacRuby/trunk/ext/openssl/ossl_x509req.c 2010-09-11 08:51:52 UTC (rev 4509) +++ MacRuby/trunk/ext/openssl/ossl_x509req.c 2010-09-13 21:18:42 UTC (rev 4510) @@ -172,8 +172,9 @@ GetX509Req(self, req); if ((len = i2d_X509_REQ(req, NULL)) <= 0) ossl_raise(eX509CertError, NULL); - str = rb_str_new(0, len); - p = (unsigned char *)RSTRING_PTR(str); + str = rb_bstr_new(); + rb_bstr_resize(str, len); + p = (unsigned char *)rb_bstr_bytes(str); if (i2d_X509_REQ(req, &p) <= 0) ossl_raise(eX509ReqError, NULL); ossl_str_adjust(str, p);