ext/camellia-rb.c in camellia-rb-1.1 vs ext/camellia-rb.c in camellia-rb-1.2

- old
+ new

@@ -1,8 +1,8 @@ /* camellia-rb.c * - * Copyright (c) 2008 + * Copyright (c) 2008-2009 * NTT (Nippon Telegraph and Telephone Corporation) . All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -26,10 +26,18 @@ */ #include <ruby.h> #include "camellia.h" #include <stdio.h> +// for version before Ruby 1.8.5 +#ifndef RSTRING_PTR +# define RSTRING_PTR(s) (RSTRING(s)->ptr) +#endif +#ifndef RSTRING_LEN +# define RSTRING_LEN(s) (RSTRING(s)->len) +#endif + typedef unsigned char u1byte; // error class static VALUE eCamellia; @@ -50,10 +58,11 @@ /* # return a new camellia object */ static VALUE s_new(VALUE self) { + camelliaObject *camellia; VALUE camellia_data; camellia = ALLOC(camelliaObject); camellia->key_gen = 0; // key is not initialized @@ -78,12 +87,12 @@ camelliaObject *camellia; Data_Get_Struct(self, camelliaObject, camellia); Check_Type(key, T_STRING); - skey_len = RSTRING(key)->len; - skey = (unsigned char *)RSTRING(key)->ptr; + skey_len = RSTRING_LEN(key); + skey = (unsigned char *)RSTRING_PTR(key); // check key length if (skey_len != 16 && skey_len != 24 && skey_len != 32) { rb_raise(rb_eArgError, "wrong key length (must be 16, 24, or 32 bytes,not %d)", skey_len); @@ -108,12 +117,12 @@ unsigned char *data; int data_len; u1byte out_blk[16]; Check_Type(args, T_STRING); - data_len = RSTRING(args)->len; - data = (unsigned char *)RSTRING(args)->ptr; + data_len = RSTRING_LEN(args); + data = (unsigned char *)RSTRING_PTR(args); Data_Get_Struct(self, camelliaObject, camellia); // check data length if (data_len != 16) @@ -144,12 +153,12 @@ unsigned char *data; int data_len; u1byte out_blk[16]; Check_Type(args, T_STRING); - data_len = RSTRING(args)->len; - data = (unsigned char *)RSTRING(args)->ptr; + data_len = RSTRING_LEN(args); + data = (unsigned char *)RSTRING_PTR(args); // check data length if (data_len != 16) { rb_raise(rb_eArgError, "wrong data length (must be 16 bytes, found %d bytes)", data_len); @@ -181,12 +190,12 @@ unsigned char *dest; int src_len; int i; Check_Type(args,T_STRING); - src = (unsigned char *)RSTRING(args)->ptr; - src_len = RSTRING(args)->len; + src = (unsigned char *)RSTRING_PTR(args); + src_len = RSTRING_LEN(args); // check IV length if (src_len != 16) { rb_raise(rb_eArgError, "wrong data length (must be 16 bytes, found %d bytes)", src_len); @@ -217,12 +226,12 @@ int srclen; int i,ch; VALUE retvalue; Check_Type(args,T_STRING); - src = (unsigned char *)RSTRING(args)->ptr; - srclen = RSTRING(args)->len; + src = (unsigned char *)RSTRING_PTR(args); + srclen = RSTRING_LEN(args); Data_Get_Struct(self,camelliaObject,camellia); // check if key is initialized if (!camellia->key_gen) @@ -270,12 +279,12 @@ int i; unsigned char ch; VALUE retvalue; Check_Type(args, T_STRING); - srclen = RSTRING(args)->len; - src = (unsigned char *)RSTRING(args)->ptr; + srclen = RSTRING_LEN(args); + src = (unsigned char *)RSTRING_PTR(args); Data_Get_Struct(self,camelliaObject, camellia); // check if key is initialized if (!camellia->key_gen) @@ -321,12 +330,12 @@ unsigned char *dest, *dest2; int src_len; int i; Check_Type(args,T_STRING); - src = (unsigned char *)RSTRING(args)->ptr; - src_len = RSTRING(args)->len; + src = (unsigned char *)RSTRING_PTR(args); + src_len = RSTRING_LEN(args); // check IV length if (src_len != 16) { rb_raise(rb_eArgError, "wrong data length (must be 16 bytes, found %d bytes)", src_len); @@ -356,12 +365,12 @@ camelliaObject *camellia; unsigned char *src; int src_len; Check_Type(args,T_STRING); - src = (unsigned char *)RSTRING(args)->ptr; - src_len = RSTRING(args)->len; + src = (unsigned char *)RSTRING_PTR(args); + src_len = RSTRING_LEN(args); // check pcharlength if (src_len != 1) { rb_raise(rb_eArgError, "wrong padding data length (must be 1 bytes, found %d bytes)", src_len); @@ -387,12 +396,12 @@ int srclen; int i, j, ch, destidx; VALUE retvalue; Check_Type(args,T_STRING); - src = (unsigned char *)RSTRING(args)->ptr; - srclen = RSTRING(args)->len; + src = (unsigned char *)RSTRING_PTR(args); + srclen = RSTRING_LEN(args); Data_Get_Struct(self,camelliaObject,camellia); // check if key is initialized if (!camellia->key_gen) @@ -465,12 +474,12 @@ int i, j, destidx; u1byte tmp[16]; VALUE retvalue; Check_Type(args, T_STRING); - srclen = RSTRING(args)->len; - src = (unsigned char *)RSTRING(args)->ptr; - + srclen = RSTRING_LEN(args); + src = (unsigned char *)RSTRING_PTR(args); + Data_Get_Struct(self,camelliaObject, camellia); // check if key is initialized if (!camellia->key_gen) {