ruby-mcrypt 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,10 @@ supports lots of different ciphers and encryption modes.
15
15
  Install the gem:
16
16
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
17
17
 
18
+ If you're installing on Ubuntu:
19
+ sudo apt-get install mcrypt libmcrypt-dev
20
+ gem install ruby-mcrypt
21
+
18
22
  If you want to run the longer test suite, do this instead:
19
23
  MCRYPT_TEST_BRUTE=1 \
20
24
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
@@ -62,7 +66,7 @@ If you find any bugs, please let the author know.
62
66
 
63
67
  == Copyright and License
64
68
 
65
- Copyright (c) 2009-2010 Philip Garrett.
69
+ Copyright (c) 2009-2013 Philip Garrett.
66
70
 
67
71
  Permission is hereby granted, free of charge, to any person obtaining a
68
72
  copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -4,7 +4,9 @@ require 'rake'
4
4
  require 'rake/testtask'
5
5
 
6
6
  # http://stackoverflow.com/questions/213368/how-can-i-reliably-discover-the-full-path-of-the-ruby-executable
7
- RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
7
+ RUBY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
8
+
9
+ ENV["MAINTAINER_MODE"] = "1" if File.exists?(File.dirname(__FILE__) + "/MAINTAINER")
8
10
 
9
11
  task :default => :test
10
12
 
@@ -25,13 +27,14 @@ rescue LoadError
25
27
  puts "Jeweler not available. Install it with: gem install jeweler"
26
28
  end
27
29
 
28
- EXTENSION = "ext/mcrypt.#{Config::CONFIG["DLEXT"]}"
30
+ EXTENSION = "ext/mcrypt.#{RbConfig::CONFIG["DLEXT"]}"
29
31
 
30
32
  desc "Compile extension"
31
33
  task :compile => EXTENSION
32
34
  file EXTENSION => FileList["ext/Makefile","ext/*.c"] do
33
35
  Dir.chdir("ext") do
34
- system("make") || raise("could not build ruby-mcrypt")
36
+ opts = ENV["MAINTAINER_MODE"] ? ["V=1"] : []
37
+ system("make", *opts) || raise("could not build ruby-mcrypt")
35
38
  end
36
39
  end
37
40
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+
3
+ [[ -s ~/.rvm/scripts/rvm ]] && source ~/.rvm/scripts/rvm
4
+
5
+ cd "$(dirname "$0")"
6
+
7
+ touch MAINTAINER
8
+
9
+ for ruby in 1.8.7 1.9.3
10
+ do
11
+ rvm use $ruby
12
+ rake clean
13
+ rake || {
14
+ echo "BUILD FAILED!" >&2
15
+ exit 1
16
+ }
17
+ done
@@ -43,4 +43,9 @@ Specifically, if you're using MacPorts, this should work for you:
43
43
  EOF
44
44
  exit 1
45
45
  end
46
+
47
+ if ENV["MAINTAINER_MODE"]
48
+ $CFLAGS += " -Werror"
49
+ end
50
+
46
51
  create_makefile(extension_name)
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * mcrypt_wrapper.c
3
3
  *
4
- * Copyright (c) 2009 Philip Garrett.
4
+ * Copyright (c) 2009-2013 Philip Garrett.
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a
7
7
  * copy of this software and associated documentation files (the
@@ -24,6 +24,7 @@
24
24
  */
25
25
 
26
26
  #include "ruby.h"
27
+ #include <limits.h>
27
28
  #include <string.h>
28
29
  #include <mcrypt.h>
29
30
 
@@ -50,6 +51,8 @@ static char *dup_rbstring(VALUE o, int include_null);
50
51
 
51
52
  static VALUE enumerate_key_sizes(int *sizes, int num_of_sizes, int max_size);
52
53
 
54
+ static int safe_len(long orig);
55
+
53
56
  /* globals */
54
57
  static VALUE cMcrypt;
55
58
  static VALUE cInvalidAlgorithmOrModeError;
@@ -106,11 +109,11 @@ static VALUE mc_initialize(int argc, VALUE *argv, VALUE self)
106
109
 
107
110
  *box = mcrypt_module_open(s_algo, NULL, s_mode, NULL);
108
111
  if (*box == MCRYPT_FAILED) {
112
+ char message[256];
109
113
  /* MCRYPT_FAILED is currently 0, but we should explicitly set
110
114
  to zero in case they change that. We don't want to attempt to
111
115
  free it later. */
112
116
  *box = 0;
113
- char message[256];
114
117
  snprintf(message, sizeof(message),
115
118
  "Could not initialize using algorithm '%s' with mode "
116
119
  "'%s'. Check mcrypt(3) for supported combinations.",
@@ -145,7 +148,7 @@ static VALUE mc_generic_init(VALUE self)
145
148
 
146
149
  rv = mcrypt_generic_init(*box,
147
150
  (void *)RSTRING_PTR(key),
148
- RSTRING_LEN(key),
151
+ safe_len(RSTRING_LEN(key)),
149
152
  RSTR_N(iv));
150
153
  if (rv < 0) {
151
154
  const char *err = mcrypt_strerror(rv);
@@ -177,7 +180,8 @@ static VALUE mc_encrypt_generic(VALUE self, VALUE plaintext)
177
180
  /* rb_str_dup doesn't actually copy the buffer, hence rb_str_new */
178
181
  ciphertext = rb_str_new(RSTRING_PTR(plaintext), RSTRING_LEN(plaintext));
179
182
 
180
- rv = mcrypt_generic(*box, (void *)RSTRING_PTR(ciphertext), RSTRING_LEN(ciphertext));
183
+ rv = mcrypt_generic(*box, (void *)RSTRING_PTR(ciphertext),
184
+ safe_len(RSTRING_LEN(ciphertext)));
181
185
  if (rv != 0)
182
186
  rb_raise(cMcryptRuntimeError, "internal error: mcrypt_generic returned %d", rv);
183
187
  return ciphertext;
@@ -196,7 +200,8 @@ static VALUE mc_decrypt_generic(VALUE self, VALUE ciphertext)
196
200
  /* rb_str_dup doesn't actually copy the buffer, hence rb_str_new */
197
201
  plaintext = rb_str_new(RSTRING_PTR(ciphertext), RSTRING_LEN(ciphertext));
198
202
 
199
- rv = mdecrypt_generic(*box, (void *)RSTRING_PTR(plaintext), RSTRING_LEN(plaintext));
203
+ rv = mdecrypt_generic(*box, (void *)RSTRING_PTR(plaintext),
204
+ safe_len(RSTRING_LEN(plaintext)));
200
205
  if (rv != 0)
201
206
  rb_raise(cMcryptRuntimeError, "internal error: mdecrypt_generic returned %d", rv);
202
207
  return plaintext;
@@ -586,3 +591,14 @@ static VALUE enumerate_key_sizes(int *sizes, int num_of_sizes, int max_size)
586
591
  return Qnil; /* quell warning */
587
592
  }
588
593
  }
594
+
595
+ static int safe_len(long orig)
596
+ {
597
+ int result = (int)orig;
598
+ if (result != orig) {
599
+ rb_raise(cMcryptRuntimeError, "The string is too large. "
600
+ "This version of mcrypt can only handle %d bytes (32-bit signed int)",
601
+ INT_MAX);
602
+ }
603
+ return result;
604
+ }
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # mcrypt.rb
3
3
  #
4
- # Copyright (c) 2009 Philip Garrett.
4
+ # Copyright (c) 2009-2013 Philip Garrett.
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a
7
7
  # copy of this software and associated documentation files (the
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby-mcrypt}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Philip Garrett"]
12
- s.date = %q{2010-08-23}
12
+ s.date = %q{2013-02-24}
13
13
  s.description = %q{= Mcrypt - libmcrypt bindings for Ruby
14
14
 
15
15
  Mcrypt provides Ruby-language bindings for libmcrypt(3), a
@@ -27,6 +27,10 @@ supports lots of different ciphers and encryption modes.
27
27
  Install the gem:
28
28
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
29
29
 
30
+ If you're installing on Ubuntu:
31
+ sudo apt-get install mcrypt libmcrypt-dev
32
+ gem install ruby-mcrypt
33
+
30
34
  If you want to run the longer test suite, do this instead:
31
35
  MCRYPT_TEST_BRUTE=1 \
32
36
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
@@ -74,7 +78,7 @@ If you find any bugs, please let the author know.
74
78
 
75
79
  == Copyright and License
76
80
 
77
- Copyright (c) 2009-2010 Philip Garrett.
81
+ Copyright (c) 2009-2013 Philip Garrett.
78
82
 
79
83
  Permission is hereby granted, free of charge, to any person obtaining a
80
84
  copy of this software and associated documentation files (the
@@ -101,44 +105,37 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
101
105
  "README.rdoc"
102
106
  ]
103
107
  s.files = [
104
- ".gitignore",
105
- "Manifest",
106
- "README.rdoc",
107
- "Rakefile",
108
- "VERSION",
109
- "ext/.gitignore",
110
- "ext/extconf.rb",
111
- "ext/mcrypt_wrapper.c",
112
- "lib/.gitignore",
113
- "lib/mcrypt.rb",
114
- "ruby-mcrypt.gemspec",
115
- "test/generate/.gitignore",
116
- "test/generate/Makefile",
117
- "test/generate/generate_testcases.c",
118
- "test/helper.rb",
119
- "test/test_basics.rb",
120
- "test/test_brute.rb",
121
- "test/test_reciprocity.rb"
108
+ "Manifest",
109
+ "README.rdoc",
110
+ "Rakefile",
111
+ "VERSION",
112
+ "cross.sh",
113
+ "ext/.gitignore",
114
+ "ext/extconf.rb",
115
+ "ext/mcrypt_wrapper.c",
116
+ "lib/.gitignore",
117
+ "lib/mcrypt.rb",
118
+ "ruby-mcrypt.gemspec",
119
+ "test/generate/.gitignore",
120
+ "test/generate/Makefile",
121
+ "test/generate/generate_testcases.c",
122
+ "test/helper.rb",
123
+ "test/test_basics.rb",
124
+ "test/test_brute.rb",
125
+ "test/test_reciprocity.rb"
122
126
  ]
123
127
  s.homepage = %q{http://github.com/kingpong/ruby-mcrypt}
124
- s.rdoc_options = ["--charset=UTF-8"]
125
128
  s.require_paths = ["lib"]
126
129
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
127
130
  s.requirements = ["libmcrypt (2.5.x or 2.6.x, tested with 2.5.8)"]
128
- s.rubygems_version = %q{1.3.7}
131
+ s.rubygems_version = %q{1.3.6}
129
132
  s.summary = %q{Ruby bindings for libmcrypt}
130
- s.test_files = [
131
- "test/helper.rb",
132
- "test/test_basics.rb",
133
- "test/test_brute.rb",
134
- "test/test_reciprocity.rb"
135
- ]
136
133
 
137
134
  if s.respond_to? :specification_version then
138
135
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
139
136
  s.specification_version = 3
140
137
 
141
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
138
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
142
139
  else
143
140
  end
144
141
  else
@@ -4,7 +4,7 @@
4
4
  * Generates a list of known-good inputs/outputs to be compared against the
5
5
  * output of ruby-mcrypt.
6
6
  *
7
- * Copyright (c) 2009 Philip Garrett.
7
+ * Copyright (c) 2009-2013 Philip Garrett.
8
8
  *
9
9
  * Permission is hereby granted, free of charge, to any person obtaining a
10
10
  * copy of this software and associated documentation files (the
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mcrypt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Philip Garrett
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-08-23 00:00:00 -04:00
17
+ date: 2013-02-24 00:00:00 -05:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -37,6 +36,10 @@ description: |
37
36
  Install the gem:
38
37
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
39
38
 
39
+ If you're installing on Ubuntu:
40
+ sudo apt-get install mcrypt libmcrypt-dev
41
+ gem install ruby-mcrypt
42
+
40
43
  If you want to run the longer test suite, do this instead:
41
44
  MCRYPT_TEST_BRUTE=1 \
42
45
  gem install ruby-mcrypt --test -- --with-mcrypt-dir=/path/to/mcrypt/prefix
@@ -84,7 +87,7 @@ description: |
84
87
 
85
88
  == Copyright and License
86
89
 
87
- Copyright (c) 2009-2010 Philip Garrett.
90
+ Copyright (c) 2009-2013 Philip Garrett.
88
91
 
89
92
  Permission is hereby granted, free of charge, to any person obtaining a
90
93
  copy of this software and associated documentation files (the
@@ -113,11 +116,11 @@ extensions:
113
116
  extra_rdoc_files:
114
117
  - README.rdoc
115
118
  files:
116
- - .gitignore
117
119
  - Manifest
118
120
  - README.rdoc
119
121
  - Rakefile
120
122
  - VERSION
123
+ - cross.sh
121
124
  - ext/.gitignore
122
125
  - ext/extconf.rb
123
126
  - ext/mcrypt_wrapper.c
@@ -136,39 +139,32 @@ homepage: http://github.com/kingpong/ruby-mcrypt
136
139
  licenses: []
137
140
 
138
141
  post_install_message:
139
- rdoc_options:
140
- - --charset=UTF-8
142
+ rdoc_options: []
143
+
141
144
  require_paths:
142
145
  - lib
143
146
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
147
  requirements:
146
148
  - - ">="
147
149
  - !ruby/object:Gem::Version
148
- hash: 59
149
150
  segments:
150
151
  - 1
151
152
  - 8
152
153
  - 6
153
154
  version: 1.8.6
154
155
  required_rubygems_version: !ruby/object:Gem::Requirement
155
- none: false
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- hash: 3
160
159
  segments:
161
160
  - 0
162
161
  version: "0"
163
162
  requirements:
164
163
  - libmcrypt (2.5.x or 2.6.x, tested with 2.5.8)
165
164
  rubyforge_project:
166
- rubygems_version: 1.3.7
165
+ rubygems_version: 1.3.6
167
166
  signing_key:
168
167
  specification_version: 3
169
168
  summary: Ruby bindings for libmcrypt
170
- test_files:
171
- - test/helper.rb
172
- - test/test_basics.rb
173
- - test/test_brute.rb
174
- - test/test_reciprocity.rb
169
+ test_files: []
170
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- .config
2
- InstalledFiles
3
- *.gem
4
- doc
5
- *.swp