base32 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  = base32
2
2
 
3
- For Version: 0.1.2
3
+ For Version: 0.1.3
4
4
 
5
5
  This package contains base32, a ruby extension for encoding and decoding
6
6
  in base32 per RFC 3548.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2009 Samuel Tesla
1
+ # Copyright (c) 2007-2011 Samuel Tesla
2
2
 
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ gemspec = Gem::Specification.new do |s|
41
41
  s.require_paths << 'ext'
42
42
  s.requirements << 'none'
43
43
  s.summary = "Ruby extension for base32 encoding and decoding"
44
- s.version = "0.1.2"
44
+ s.version = "0.1.3"
45
45
  end
46
46
 
47
47
  Rake::GemPackageTask.new(gemspec) do |pkg|
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2009 Samuel Tesla
1
+ # Copyright (c) 2007-2011 Samuel Tesla
2
2
 
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- /* Copyright (c) 2007-2009 Samuel Tesla
1
+ /* Copyright (c) 2007-2011 Samuel Tesla
2
2
  *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- /* Copyright (c) 2007-2009 Samuel Tesla
1
+ /* Copyright (c) 2007-2011 Samuel Tesla
2
2
  *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- /* Copyright (c) 2007-2009 Samuel Tesla
1
+ /* Copyright (c) 2007-2011 Samuel Tesla
2
2
  *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- /* Copyright (c) 2007-2009 Samuel Tesla
1
+ /* Copyright (c) 2007-2011 Samuel Tesla
2
2
  *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
data/ext/ext.c CHANGED
@@ -1,4 +1,4 @@
1
- /* Copyright (c) 2007-2009 Samuel Tesla
1
+ /* Copyright (c) 2007-2011 Samuel Tesla
2
2
  *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
@@ -35,19 +35,28 @@ static VALUE
35
35
  b32_decode (VALUE self, VALUE value)
36
36
  {
37
37
  value = StringValue (value);
38
- if (RSTRING (value)->len == 0)
38
+ if (RSTRING_LEN (value) == 0)
39
39
  return value;
40
40
 
41
- VALUE result = rb_str_new (0, base32_decode_buffer_size (RSTRING (value)->len));
41
+ size_t buflen = base32_decode_buffer_size (RSTRING_LEN (value));
42
+ char *buffer = (char *) malloc (buflen);
42
43
  #ifdef TEST
43
- memset(RSTRING (result)->ptr, 0xff, RSTRING (result)->len);
44
+ memset(buffer, 0xff, buflen);
45
+ #else
46
+ memset(buffer, 0x00, buflen);
44
47
  #endif
45
- size_t length = base32_decode ((uint8_t *) RSTRING (result)->ptr, RSTRING (result)->len,
46
- (uint8_t *) RSTRING (value)->ptr, RSTRING (value)->len);
47
- if (length == 0)
48
+
49
+ size_t length = base32_decode ((uint8_t *) buffer, buflen,
50
+ (uint8_t *) RSTRING_PTR (value), RSTRING_LEN (value));
51
+
52
+ if (length == 0) {
53
+ free(buffer);
48
54
  rb_raise(rb_eRuntimeError, "Value provided not base32 encoded");
55
+ }
49
56
 
50
- RSTRING (result)->len = length;
57
+ VALUE result = rb_str_new (0, length);
58
+ memcpy(RSTRING_PTR (result), buffer, length);
59
+ free(buffer);
51
60
  return result;
52
61
  }
53
62
 
@@ -62,12 +71,12 @@ b32_encode (VALUE self, VALUE value)
62
71
  {
63
72
  value = StringValue(value);
64
73
 
65
- VALUE result = rb_str_new (0, base32_encoder_buffer_size (RSTRING (value)->len));
74
+ VALUE result = rb_str_new (0, base32_encoder_buffer_size (RSTRING_LEN (value)));
66
75
  #ifdef TEST
67
- memset(RSTRING (result)->ptr, 0xff, RSTRING (result)->len);
76
+ memset(RSTRING_PTR (result), 0xff, RSTRING_LEN (result));
68
77
  #endif
69
- base32_encode ((uint8_t *) RSTRING (result)->ptr, RSTRING (result)->len,
70
- (uint8_t *) RSTRING (value)->ptr, RSTRING (value)->len);
78
+ base32_encode ((uint8_t *) RSTRING_PTR (result), RSTRING_LEN (result),
79
+ (uint8_t *) RSTRING_PTR (value), RSTRING_LEN (value));
71
80
 
72
81
  return result;
73
82
  }
@@ -76,7 +85,7 @@ b32_encode (VALUE self, VALUE value)
76
85
  static VALUE
77
86
  b32_test_strlen (VALUE self, VALUE value)
78
87
  {
79
- return UINT2NUM (strlen (RSTRING (value)->ptr));
88
+ return UINT2NUM (strlen (RSTRING_PTR (value)));
80
89
  }
81
90
  #endif
82
91
 
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2009 Samuel Tesla
1
+ # Copyright (c) 2007-2011 Samuel Tesla
2
2
 
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2007-2009 Samuel Tesla
1
+ # Copyright (c) 2007-2011 Samuel Tesla
2
2
 
3
3
  # Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  # of this software and associated documentation files (the "Software"), to deal
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base32
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 3
10
+ version: 0.1.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Samuel Tesla
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-06 00:00:00 -06:00
18
+ date: 2011-03-31 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -43,21 +49,27 @@ require_paths:
43
49
  - lib
44
50
  - ext
45
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
46
53
  requirements:
47
54
  - - ">="
48
55
  - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
49
59
  version: "0"
50
- version:
51
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
52
62
  requirements:
53
63
  - - ">="
54
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
55
68
  version: "0"
56
- version:
57
69
  requirements:
58
70
  - none
59
71
  rubyforge_project:
60
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.5.0
61
73
  signing_key:
62
74
  specification_version: 3
63
75
  summary: Ruby extension for base32 encoding and decoding