summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_asn1.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-30 19:09:03 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-30 19:09:03 +0000
commitfbc87479bba634a9a9c26e672e2806ad528a2f46 (patch)
tree2ed20d71ab2ee3558cca2f119de2a92017919289 /ext/openssl/ossl_asn1.c
parent7922fdd795604d8e6a1589cfbb0f4b9f8cf21eb3 (diff)
* ext/openssl/ossl_asn1.c (ossl_i2d_ASN1_TYPE, ossl_ASN1_TYPE_free):
workaround for the versions earlier than OpenSSL-0.9.7. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6552 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_asn1.c')
-rw-r--r--ext/openssl/ossl_asn1.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/ext/openssl/ossl_asn1.c b/ext/openssl/ossl_asn1.c
index 09ca66f..7d36471 100644
--- a/ext/openssl/ossl_asn1.c
+++ b/ext/openssl/ossl_asn1.c
@@ -189,7 +189,7 @@ static ID sUNIVERSAL, sAPPLICATION, sCONTEXT_SPECIFIC, sPRIVATE;
static ASN1_BOOLEAN
obj_to_asn1bool(VALUE obj)
{
- return RTEST(obj) ? 255 : 0;
+ return RTEST(obj) ? 0xff : 0x100;
}
static ASN1_INTEGER*
@@ -886,6 +886,30 @@ ossl_asn1_initialize(int argc, VALUE *argv, VALUE self)
return self;
}
+static int
+ossl_i2d_ASN1_TYPE(ASN1_TYPE *a, unsigned char **pp)
+{
+#if OPENSSL_VERSION_NUMBER < 0x00907000L
+ if(!a) return 0;
+ if(a->type == V_ASN1_BOOLEAN)
+ return i2d_ASN1_BOOLEAN(a->value.boolean, pp);
+#endif
+ return i2d_ASN1_TYPE(a, pp);
+}
+
+static void
+ossl_ASN1_TYPE_free(ASN1_TYPE *a)
+{
+#if OPENSSL_VERSION_NUMBER < 0x00907000L
+ if(!a) return;
+ if(a->type == V_ASN1_BOOLEAN){
+ OPENSSL_free(a);
+ return;
+ }
+#endif
+ ASN1_TYPE_free(a);
+}
+
static VALUE
ossl_asn1prim_to_der(VALUE self)
{
@@ -900,24 +924,24 @@ ossl_asn1prim_to_der(VALUE self)
explicit = ossl_asn1_is_explicit(self);
asn1 = ossl_asn1_get_asn1type(self);
- length = ASN1_object_size(1, i2d_ASN1_TYPE(asn1, NULL), tn);
+ length = ASN1_object_size(1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn);
if(!(buf = OPENSSL_malloc(length))){
- ASN1_TYPE_free(asn1);
+ ossl_ASN1_TYPE_free(asn1);
ossl_raise(eASN1Error, "cannot alloc buffer");
}
p = buf;
- if(tc == V_ASN1_UNIVERSAL) i2d_ASN1_TYPE(asn1, &p);
+ if(tc == V_ASN1_UNIVERSAL) ossl_i2d_ASN1_TYPE(asn1, &p);
else{
if(explicit){
- ASN1_put_object(&p, 1, i2d_ASN1_TYPE(asn1, NULL), tn, tc);
- i2d_ASN1_TYPE(asn1, &p);
+ ASN1_put_object(&p, 1, ossl_i2d_ASN1_TYPE(asn1, NULL), tn, tc);
+ ossl_i2d_ASN1_TYPE(asn1, &p);
}
else{
- i2d_ASN1_TYPE(asn1, &p);
+ ossl_i2d_ASN1_TYPE(asn1, &p);
*buf = tc | tn | (*buf & V_ASN1_CONSTRUCTED);
}
}
- ASN1_TYPE_free(asn1);
+ ossl_ASN1_TYPE_free(asn1);
reallen = p - buf;
assert(reallen <= length);
str = ossl_buf2str(buf, reallen); /* buf will be free in ossl_buf2str */