id_shuffler 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/ext/id_shuffler/id_shuffler.c +18 -19
  2. metadata +1 -1
@@ -32,9 +32,8 @@
32
32
  */
33
33
 
34
34
  const int i = 1;
35
- #define is_bigendian() ( (*(char*)&i) == 0 )
36
35
 
37
- const char ftable[256] = {
36
+ const unsigned char ftable[256] = {
38
37
  0xa3,0xd7,0x09,0x83,0xf8,0x48,0xf6,0xf4,0xb3,0x21,0x15,0x78,0x99,0xb1,0xaf,0xf9,
39
38
  0xe7,0x2d,0x4d,0x8a,0xce,0x4c,0xca,0x2e,0x52,0x95,0xd9,0x1e,0x4e,0x38,0x44,0x28,
40
39
  0x0a,0xdf,0x02,0xa0,0x17,0xf1,0x60,0x68,0x12,0xb7,0x7a,0xc3,0xe9,0xfa,0x3d,0x53,
@@ -53,7 +52,7 @@ const char ftable[256] = {
53
52
  0x5e,0x6c,0xa9,0x13,0x57,0x25,0xb5,0xe3,0xbd,0xa8,0x3a,0x01,0x05,0x59,0x2a,0x46
54
53
  };
55
54
 
56
- uint32_t g(char key[10], int k, uint32_t w)
55
+ uint32_t g(unsigned char key[10], int k, uint32_t w)
57
56
  {
58
57
  uint8_t g1, g2, g3, g4, g5, g6;
59
58
 
@@ -73,16 +72,16 @@ static VALUE r_is_big_endian(VALUE self) {
73
72
  }
74
73
 
75
74
  static VALUE r_g1(VALUE self) {
76
- char key[10] = {1,2,3,4,5,6,7,8,9,10};
75
+ unsigned char key[10] = {1,2,3,4,5,6,7,8,9,10};
77
76
  return ULONG2NUM(g(key,1,1));
78
77
  }
79
78
 
80
79
  static VALUE r_g2(VALUE self) {
81
- char key[10] = {1,2,3,4,5,6,7,8,9,10};
80
+ unsigned char key[10] = {1,2,3,4,5,6,7,8,9,10};
82
81
  return ULONG2NUM(g(key,1,32767));
83
82
  }
84
83
 
85
- uint32_t skip30(char key[10], uint32_t num, int encrypt)
84
+ uint32_t skip30(unsigned char key[10], uint32_t num, int encrypt)
86
85
  {
87
86
  int k; /* round number */
88
87
  int i; /* round counter */
@@ -111,17 +110,17 @@ uint32_t skip30(char key[10], uint32_t num, int encrypt)
111
110
  }
112
111
 
113
112
  static VALUE r_skip1(VALUE self) {
114
- char key[10] = {1,2,3,4,5,6,7,8,9,10};
113
+ unsigned char key[10] = {1,2,3,4,5,6,7,8,9,10};
115
114
  return ULONG2NUM(skip30(key,1,1));
116
115
  }
117
116
 
118
117
  static VALUE r_skip2(VALUE self) {
119
- char key[10] = {1,2,3,4,5,6,7,8,9,10};
118
+ unsigned char key[10] = {1,2,3,4,5,6,7,8,9,10};
120
119
  return ULONG2NUM(skip30(key,32767,1));
121
120
  }
122
121
 
123
122
  static VALUE r_skip3(VALUE self, VALUE original_num) {
124
- char key[10] = {1,2,3,4,5,6,7,8,9,10};
123
+ unsigned char key[10] = {1,2,3,4,5,6,7,8,9,10};
125
124
  unsigned long original_ulong;
126
125
  original_ulong = NUM2ULONG(original_num);
127
126
  uint32_t original = original_ulong;
@@ -129,7 +128,7 @@ static VALUE r_skip3(VALUE self, VALUE original_num) {
129
128
  }
130
129
 
131
130
  static VALUE r_skip4(VALUE self, VALUE original_num, VALUE key_str) {
132
- char *key = StringValuePtr(key_str);
131
+ unsigned char *key = StringValuePtr(key_str);
133
132
  unsigned long original_ulong;
134
133
  original_ulong = NUM2ULONG(original_num);
135
134
  uint32_t original = original_ulong;
@@ -155,7 +154,7 @@ static VALUE r_base32_shuffle(VALUE self, VALUE original_num, VALUE key_str) {
155
154
  /* convert from ruby objects */
156
155
  unsigned long original_ulong;
157
156
  original_ulong = NUM2ULONG(original_num);
158
- char *key = StringValuePtr(key_str);
157
+ unsigned char *key = StringValuePtr(key_str);
159
158
 
160
159
  /* bounds check the id */
161
160
  if (original_ulong >= (1 << 30)) {
@@ -173,8 +172,8 @@ static VALUE r_base32_shuffle(VALUE self, VALUE original_num, VALUE key_str) {
173
172
  uint32_t shuffled = skip30(key, original, 1);
174
173
 
175
174
  /* base-32 encode the result using "crockford 32" alphabet */
176
- char buf[6];
177
- char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
175
+ unsigned char buf[6];
176
+ unsigned char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
178
177
  int cpos;
179
178
  for (cpos = 0; cpos < 6; cpos ++) {
180
179
  buf[cpos] = digits[((shuffled >> (5*(5-cpos))) & 31)];
@@ -185,8 +184,8 @@ static VALUE r_base32_shuffle(VALUE self, VALUE original_num, VALUE key_str) {
185
184
  }
186
185
 
187
186
  static VALUE r_b32(VALUE self, VALUE original_num) {
188
- char buf[6];
189
- char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
187
+ unsigned char buf[6];
188
+ unsigned char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
190
189
  int cpos;
191
190
  unsigned long original_ulong;
192
191
  original_ulong = NUM2ULONG(original_num);
@@ -207,20 +206,20 @@ static VALUE r_base32_unshuffle(VALUE self, VALUE shuffled_str, VALUE key_str) {
207
206
  * -> "a" etc. */
208
207
 
209
208
  /* convert from ruby string to char buf */
210
- char *b32 = StringValuePtr(shuffled_str);
209
+ unsigned char *b32 = StringValuePtr(shuffled_str);
211
210
  if (RSTRING_LEN(shuffled_str) != 6) {
212
211
  /* must be 6 base-32 digits */
213
212
  return INT2NUM(-1);
214
213
  }
215
- char *key = StringValuePtr(key_str);
214
+ unsigned char *key = StringValuePtr(key_str);
216
215
  if (RSTRING_LEN(key_str) < 10) {
217
216
  return rb_str_new2("invalid key length");
218
217
  }
219
218
 
220
219
  /* remove base32 encoding */
221
220
  uint32_t shuffled = 0;
222
- char *found;
223
- char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
221
+ unsigned char *found;
222
+ unsigned char *digits = "0123456789abcdefghjkmnpqrstvwxyz";
224
223
  int cpos = 0;
225
224
  for (cpos = 0; cpos < 6; cpos++) {
226
225
  found = strchr(digits,b32[cpos]);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id_shuffler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: