bcrypt 3.1.12 → 3.1.20

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/ext/mri/x86.S ADDED
@@ -0,0 +1,203 @@
1
+ /*
2
+ * Written by Solar Designer <solar at openwall.com> in 1998-2010.
3
+ * No copyright is claimed, and the software is hereby placed in the public
4
+ * domain. In case this attempt to disclaim copyright and place the software
5
+ * in the public domain is deemed null and void, then the software is
6
+ * Copyright (c) 1998-2010 Solar Designer and it is hereby released to the
7
+ * general public under the following terms:
8
+ *
9
+ * Redistribution and use in source and binary forms, with or without
10
+ * modification, are permitted.
11
+ *
12
+ * There's ABSOLUTELY NO WARRANTY, express or implied.
13
+ *
14
+ * See crypt_blowfish.c for more information.
15
+ */
16
+
17
+ #ifdef __i386__
18
+
19
+ #if defined(__OpenBSD__) && !defined(__ELF__)
20
+ #define UNDERSCORES
21
+ #define ALIGN_LOG
22
+ #endif
23
+
24
+ #if defined(__CYGWIN32__) || defined(__MINGW32__)
25
+ #define UNDERSCORES
26
+ #endif
27
+
28
+ #ifdef __DJGPP__
29
+ #define UNDERSCORES
30
+ #define ALIGN_LOG
31
+ #endif
32
+
33
+ #ifdef UNDERSCORES
34
+ #define _BF_body_r __BF_body_r
35
+ #endif
36
+
37
+ #ifdef ALIGN_LOG
38
+ #define DO_ALIGN(log) .align (log)
39
+ #elif defined(DUMBAS)
40
+ #define DO_ALIGN(log) .align 1 << log
41
+ #else
42
+ #define DO_ALIGN(log) .align (1 << (log))
43
+ #endif
44
+
45
+ #define BF_FRAME 0x200
46
+ #define ctx %esp
47
+
48
+ #define BF_ptr (ctx)
49
+
50
+ #define S(N, r) N+BF_FRAME(ctx,r,4)
51
+ #ifdef DUMBAS
52
+ #define P(N) 0x1000+N+N+N+N+BF_FRAME(ctx)
53
+ #else
54
+ #define P(N) 0x1000+4*N+BF_FRAME(ctx)
55
+ #endif
56
+
57
+ /*
58
+ * This version of the assembly code is optimized primarily for the original
59
+ * Intel Pentium but is also careful to avoid partial register stalls on the
60
+ * Pentium Pro family of processors (tested up to Pentium III Coppermine).
61
+ *
62
+ * It is possible to do 15% faster on the Pentium Pro family and probably on
63
+ * many non-Intel x86 processors, but, unfortunately, that would make things
64
+ * twice slower for the original Pentium.
65
+ *
66
+ * An additional 2% speedup may be achieved with non-reentrant code.
67
+ */
68
+
69
+ #define L %esi
70
+ #define R %edi
71
+ #define tmp1 %eax
72
+ #define tmp1_lo %al
73
+ #define tmp2 %ecx
74
+ #define tmp2_hi %ch
75
+ #define tmp3 %edx
76
+ #define tmp3_lo %dl
77
+ #define tmp4 %ebx
78
+ #define tmp4_hi %bh
79
+ #define tmp5 %ebp
80
+
81
+ .text
82
+
83
+ #define BF_ROUND(L, R, N) \
84
+ xorl L,tmp2; \
85
+ xorl tmp1,tmp1; \
86
+ movl tmp2,L; \
87
+ shrl $16,tmp2; \
88
+ movl L,tmp4; \
89
+ movb tmp2_hi,tmp1_lo; \
90
+ andl $0xFF,tmp2; \
91
+ movb tmp4_hi,tmp3_lo; \
92
+ andl $0xFF,tmp4; \
93
+ movl S(0,tmp1),tmp1; \
94
+ movl S(0x400,tmp2),tmp5; \
95
+ addl tmp5,tmp1; \
96
+ movl S(0x800,tmp3),tmp5; \
97
+ xorl tmp5,tmp1; \
98
+ movl S(0xC00,tmp4),tmp5; \
99
+ addl tmp1,tmp5; \
100
+ movl 4+P(N),tmp2; \
101
+ xorl tmp5,R
102
+
103
+ #define BF_ENCRYPT_START \
104
+ BF_ROUND(L, R, 0); \
105
+ BF_ROUND(R, L, 1); \
106
+ BF_ROUND(L, R, 2); \
107
+ BF_ROUND(R, L, 3); \
108
+ BF_ROUND(L, R, 4); \
109
+ BF_ROUND(R, L, 5); \
110
+ BF_ROUND(L, R, 6); \
111
+ BF_ROUND(R, L, 7); \
112
+ BF_ROUND(L, R, 8); \
113
+ BF_ROUND(R, L, 9); \
114
+ BF_ROUND(L, R, 10); \
115
+ BF_ROUND(R, L, 11); \
116
+ BF_ROUND(L, R, 12); \
117
+ BF_ROUND(R, L, 13); \
118
+ BF_ROUND(L, R, 14); \
119
+ BF_ROUND(R, L, 15); \
120
+ movl BF_ptr,tmp5; \
121
+ xorl L,tmp2; \
122
+ movl P(17),L
123
+
124
+ #define BF_ENCRYPT_END \
125
+ xorl R,L; \
126
+ movl tmp2,R
127
+
128
+ DO_ALIGN(5)
129
+ .globl _BF_body_r
130
+ _BF_body_r:
131
+ movl 4(%esp),%eax
132
+ pushl %ebp
133
+ pushl %ebx
134
+ pushl %esi
135
+ pushl %edi
136
+ subl $BF_FRAME-8,%eax
137
+ xorl L,L
138
+ cmpl %esp,%eax
139
+ ja BF_die
140
+ xchgl %eax,%esp
141
+ xorl R,R
142
+ pushl %eax
143
+ leal 0x1000+BF_FRAME-4(ctx),%eax
144
+ movl 0x1000+BF_FRAME-4(ctx),tmp2
145
+ pushl %eax
146
+ xorl tmp3,tmp3
147
+ BF_loop_P:
148
+ BF_ENCRYPT_START
149
+ addl $8,tmp5
150
+ BF_ENCRYPT_END
151
+ leal 0x1000+18*4+BF_FRAME(ctx),tmp1
152
+ movl tmp5,BF_ptr
153
+ cmpl tmp5,tmp1
154
+ movl L,-8(tmp5)
155
+ movl R,-4(tmp5)
156
+ movl P(0),tmp2
157
+ ja BF_loop_P
158
+ leal BF_FRAME(ctx),tmp5
159
+ xorl tmp3,tmp3
160
+ movl tmp5,BF_ptr
161
+ BF_loop_S:
162
+ BF_ENCRYPT_START
163
+ BF_ENCRYPT_END
164
+ movl P(0),tmp2
165
+ movl L,(tmp5)
166
+ movl R,4(tmp5)
167
+ BF_ENCRYPT_START
168
+ BF_ENCRYPT_END
169
+ movl P(0),tmp2
170
+ movl L,8(tmp5)
171
+ movl R,12(tmp5)
172
+ BF_ENCRYPT_START
173
+ BF_ENCRYPT_END
174
+ movl P(0),tmp2
175
+ movl L,16(tmp5)
176
+ movl R,20(tmp5)
177
+ BF_ENCRYPT_START
178
+ addl $32,tmp5
179
+ BF_ENCRYPT_END
180
+ leal 0x1000+BF_FRAME(ctx),tmp1
181
+ movl tmp5,BF_ptr
182
+ cmpl tmp5,tmp1
183
+ movl P(0),tmp2
184
+ movl L,-8(tmp5)
185
+ movl R,-4(tmp5)
186
+ ja BF_loop_S
187
+ movl 4(%esp),%esp
188
+ popl %edi
189
+ popl %esi
190
+ popl %ebx
191
+ popl %ebp
192
+ ret
193
+
194
+ BF_die:
195
+ /* Oops, need to re-compile with a larger BF_FRAME. */
196
+ hlt
197
+ jmp BF_die
198
+
199
+ #endif
200
+
201
+ #if defined(__ELF__) && defined(__linux__)
202
+ .section .note.GNU-stack,"",%progbits
203
+ #endif
data/lib/bcrypt/engine.rb CHANGED
@@ -2,9 +2,19 @@ module BCrypt
2
2
  # A Ruby wrapper for the bcrypt() C extension calls and the Java calls.
3
3
  class Engine
4
4
  # The default computational expense parameter.
5
- DEFAULT_COST = 10
5
+ DEFAULT_COST = 12
6
6
  # The minimum cost supported by the algorithm.
7
7
  MIN_COST = 4
8
+ # The maximum cost supported by the algorithm.
9
+ MAX_COST = 31
10
+ # Maximum possible size of bcrypt() secrets.
11
+ # Older versions of the bcrypt library would truncate passwords longer
12
+ # than 72 bytes, but newer ones do not. We truncate like the old library for
13
+ # forward compatibility. This way users upgrading from Ubuntu 18.04 to 20.04
14
+ # will not have their user passwords invalidated, for example.
15
+ # A max secret length greater than 255 leads to bcrypt returning nil.
16
+ # https://github.com/bcrypt-ruby/bcrypt-ruby/issues/225#issuecomment-875908425
17
+ MAX_SECRET_BYTESIZE = 72
8
18
  # Maximum possible size of bcrypt() salts.
9
19
  MAX_SALT_LENGTH = 16
10
20
 
@@ -28,8 +38,8 @@ module BCrypt
28
38
  #
29
39
  # Example:
30
40
  #
31
- # BCrypt::Engine::DEFAULT_COST #=> 10
32
- # BCrypt::Password.create('secret').cost #=> 10
41
+ # BCrypt::Engine::DEFAULT_COST #=> 12
42
+ # BCrypt::Password.create('secret').cost #=> 12
33
43
  #
34
44
  # BCrypt::Engine.cost = 8
35
45
  # BCrypt::Password.create('secret').cost #=> 8
@@ -41,14 +51,23 @@ module BCrypt
41
51
  end
42
52
 
43
53
  # Given a secret and a valid salt (see BCrypt::Engine.generate_salt) calculates
44
- # a bcrypt() password hash.
54
+ # a bcrypt() password hash. Secrets longer than 72 bytes are truncated.
45
55
  def self.hash_secret(secret, salt, _ = nil)
56
+ unless _.nil?
57
+ warn "[DEPRECATION] Passing the third argument to " \
58
+ "`BCrypt::Engine.hash_secret` is deprecated. " \
59
+ "Please do not pass the third argument which " \
60
+ "is currently not used."
61
+ end
62
+
46
63
  if valid_secret?(secret)
47
64
  if valid_salt?(salt)
48
65
  if RUBY_PLATFORM == "java"
49
- Java.bcrypt_jruby.BCrypt.hashpw(secret.to_s, salt.to_s)
66
+ Java.bcrypt_jruby.BCrypt.hashpw(secret.to_s.to_java_bytes, salt.to_s)
50
67
  else
51
- __bc_crypt(secret.to_s, salt)
68
+ secret = secret.to_s
69
+ secret = secret.byteslice(0, MAX_SECRET_BYTESIZE) if secret && secret.bytesize > MAX_SECRET_BYTESIZE
70
+ __bc_crypt(secret, salt)
52
71
  end
53
72
  else
54
73
  raise Errors::InvalidSalt.new("invalid salt")
@@ -68,8 +87,7 @@ module BCrypt
68
87
  if RUBY_PLATFORM == "java"
69
88
  Java.bcrypt_jruby.BCrypt.gensalt(cost)
70
89
  else
71
- prefix = "$2a$05$CCCCCCCCCCCCCCCCCCCCC.E5YPO9kmyuRGyh0XouQYb4YMJKvyOeW"
72
- __bc_salt(prefix, cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH))
90
+ __bc_salt("$2a$", cost, OpenSSL::Random.random_bytes(MAX_SALT_LENGTH))
73
91
  end
74
92
  else
75
93
  raise Errors::InvalidCost.new("cost must be numeric and > 0")
@@ -78,7 +96,7 @@ module BCrypt
78
96
 
79
97
  # Returns true if +salt+ is a valid bcrypt() salt, false if not.
80
98
  def self.valid_salt?(salt)
81
- !!(salt =~ /^\$[0-9a-z]{2,}\$[0-9]{2,}\$[A-Za-z0-9\.\/]{22,}$/)
99
+ !!(salt =~ /\A\$[0-9a-z]{2,}\$[0-9]{2,}\$[A-Za-z0-9\.\/]{22,}\z/)
82
100
  end
83
101
 
84
102
  # Returns true if +secret+ is a valid bcrypt() secret, false if not.
@@ -99,7 +117,7 @@ module BCrypt
99
117
  # # should take less than 1000ms
100
118
  # BCrypt::Password.create("woo", :cost => 12)
101
119
  def self.calibrate(upper_time_limit_in_ms)
102
- 40.times do |i|
120
+ (BCrypt::Engine::MIN_COST..BCrypt::Engine::MAX_COST-1).each do |i|
103
121
  start_time = Time.now
104
122
  Password.create("testing testing", :cost => i+1)
105
123
  end_time = Time.now - start_time
@@ -7,7 +7,7 @@ module BCrypt
7
7
  #
8
8
  # # hash a user's password
9
9
  # @password = Password.create("my grand secret")
10
- # @password #=> "$2a$10$GtKs1Kbsig8ULHZzO1h2TetZfhO4Fmlxphp8bVKnUlZCBYYClPohG"
10
+ # @password #=> "$2a$12$C5.FIvVDS9W4AYZ/Ib37YuWd/7ozp1UaMhU28UKrfSxp2oDchbi3K"
11
11
  #
12
12
  # # store it safely
13
13
  # @user.update_attribute(:password, @password)
@@ -42,12 +42,12 @@ module BCrypt
42
42
  # @password = BCrypt::Password.create("my secret", :cost => 13)
43
43
  def create(secret, options = {})
44
44
  cost = options[:cost] || BCrypt::Engine.cost
45
- raise ArgumentError if cost > 31
45
+ raise ArgumentError if cost > BCrypt::Engine::MAX_COST
46
46
  Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(cost)))
47
47
  end
48
48
 
49
49
  def valid_hash?(h)
50
- h =~ /^\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}$/
50
+ /\A\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}\z/ === h
51
51
  end
52
52
  end
53
53
 
@@ -62,6 +62,17 @@ module BCrypt
62
62
  end
63
63
 
64
64
  # Compares a potential secret against the hash. Returns true if the secret is the original secret, false otherwise.
65
+ #
66
+ # Comparison edge case/gotcha:
67
+ #
68
+ # secret = "my secret"
69
+ # @password = BCrypt::Password.create(secret)
70
+ #
71
+ # @password == secret # => True
72
+ # @password == @password # => False
73
+ # @password == @password.to_s # => False
74
+ # @password.to_s == @password # => True
75
+ # @password.to_s == @password.to_s # => True
65
76
  def ==(secret)
66
77
  super(BCrypt::Engine.hash_secret(secret, @salt))
67
78
  end
@@ -83,5 +94,4 @@ module BCrypt
83
94
  return v.to_str, c.to_i, h[0, 29].to_str, mash[-31, 31].to_str
84
95
  end
85
96
  end
86
-
87
97
  end
data/lib/bcrypt.rb CHANGED
@@ -9,12 +9,7 @@ else
9
9
  require "openssl"
10
10
  end
11
11
 
12
- begin
13
- RUBY_VERSION =~ /(\d+.\d+)/
14
- require "#{$1}/bcrypt_ext"
15
- rescue LoadError
16
- require "bcrypt_ext"
17
- end
12
+ require "bcrypt_ext"
18
13
 
19
14
  require 'bcrypt/error'
20
15
  require 'bcrypt/engine'
metadata CHANGED
@@ -1,60 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcrypt
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.12
4
+ version: 3.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Coda Hale
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-16 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.2
19
+ version: 1.2.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.2
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3'
41
- - !ruby/object:Gem::Dependency
42
- name: rdoc
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '3.12'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '3.12'
55
- description: ! " bcrypt() is a sophisticated and secure hash algorithm designed
56
- by The OpenBSD project\n for hashing passwords. The bcrypt Ruby gem provides
57
- a simple wrapper for safely handling\n passwords.\n"
41
+ description: |2
42
+ bcrypt() is a sophisticated and secure hash algorithm designed by The OpenBSD project
43
+ for hashing passwords. The bcrypt Ruby gem provides a simple wrapper for safely handling
44
+ passwords.
58
45
  email: coda.hale@gmail.com
59
46
  executables: []
60
47
  extensions:
@@ -63,68 +50,57 @@ extra_rdoc_files:
63
50
  - README.md
64
51
  - COPYING
65
52
  - CHANGELOG
66
- - lib/bcrypt/password.rb
67
53
  - lib/bcrypt/engine.rb
68
54
  - lib/bcrypt/error.rb
55
+ - lib/bcrypt/password.rb
69
56
  - lib/bcrypt.rb
70
57
  files:
71
- - .gitignore
72
- - .rspec
73
- - .travis.yml
74
58
  - CHANGELOG
75
59
  - COPYING
76
- - Gemfile
77
- - Gemfile.lock
78
60
  - README.md
79
- - Rakefile
80
- - appveyor.yml
81
- - bcrypt.gemspec
82
61
  - ext/jruby/bcrypt_jruby/BCrypt.java
83
62
  - ext/mri/bcrypt_ext.c
84
63
  - ext/mri/crypt.c
85
64
  - ext/mri/crypt.h
86
65
  - ext/mri/crypt_blowfish.c
66
+ - ext/mri/crypt_blowfish.h
87
67
  - ext/mri/crypt_gensalt.c
68
+ - ext/mri/crypt_gensalt.h
88
69
  - ext/mri/extconf.rb
89
70
  - ext/mri/ow-crypt.h
90
71
  - ext/mri/wrapper.c
72
+ - ext/mri/x86.S
91
73
  - lib/bcrypt.rb
92
74
  - lib/bcrypt/engine.rb
93
75
  - lib/bcrypt/error.rb
94
76
  - lib/bcrypt/password.rb
95
- - spec/TestBCrypt.java
96
- - spec/bcrypt/engine_spec.rb
97
- - spec/bcrypt/error_spec.rb
98
- - spec/bcrypt/password_spec.rb
99
- - spec/spec_helper.rb
100
- homepage: https://github.com/codahale/bcrypt-ruby
77
+ homepage: https://github.com/bcrypt-ruby/bcrypt-ruby
101
78
  licenses:
102
79
  - MIT
103
80
  metadata: {}
104
- post_install_message:
81
+ post_install_message:
105
82
  rdoc_options:
106
- - --title
83
+ - "--title"
107
84
  - bcrypt-ruby
108
- - --line-numbers
109
- - --inline-source
110
- - --main
85
+ - "--line-numbers"
86
+ - "--inline-source"
87
+ - "--main"
111
88
  - README.md
112
89
  require_paths:
113
90
  - lib
114
91
  required_ruby_version: !ruby/object:Gem::Requirement
115
92
  requirements:
116
- - - ! '>='
93
+ - - ">="
117
94
  - !ruby/object:Gem::Version
118
95
  version: '0'
119
96
  required_rubygems_version: !ruby/object:Gem::Requirement
120
97
  requirements:
121
- - - ! '>='
98
+ - - ">="
122
99
  - !ruby/object:Gem::Version
123
100
  version: '0'
124
101
  requirements: []
125
- rubyforge_project:
126
- rubygems_version: 2.7.6
127
- signing_key:
102
+ rubygems_version: 3.4.10
103
+ signing_key:
128
104
  specification_version: 4
129
105
  summary: OpenBSD's bcrypt() password hashing algorithm.
130
106
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- doc
2
- pkg
3
- tmp
4
- *.o
5
- *.bundle
6
- *.so
7
- *.jar
8
- .DS_Store
9
- .rbenv-gemsets
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --backtrace
3
- --format documentation
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - gem update --system
4
- - gem install bundler
5
- rvm:
6
- - 1.8
7
- - 1.9
8
- - 2.0
9
- - 2.1
10
- - 2.2
11
- - 2.3
12
- - 2.4
13
- - 2.5
14
- - 2.6
15
- - ruby-head
16
- - jruby-18mode
17
- - jruby-19mode
18
- - jruby-head
19
- - rbx-3
20
- - ree
21
- script: bundle exec rake
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source 'https://rubygems.org'
2
- gemspec
data/Gemfile.lock DELETED
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bcrypt (3.1.12)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.2.5)
10
- json (1.8.6)
11
- json (1.8.6-java)
12
- rake (10.4.2)
13
- rake-compiler (0.9.5)
14
- rake
15
- rdoc (3.12.2)
16
- json (~> 1.4)
17
- rspec (3.3.0)
18
- rspec-core (~> 3.3.0)
19
- rspec-expectations (~> 3.3.0)
20
- rspec-mocks (~> 3.3.0)
21
- rspec-core (3.3.2)
22
- rspec-support (~> 3.3.0)
23
- rspec-expectations (3.3.1)
24
- diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.3.0)
26
- rspec-mocks (3.3.2)
27
- diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.3.0)
29
- rspec-support (3.3.0)
30
-
31
- PLATFORMS
32
- java
33
- ruby
34
- x64-mingw32
35
- x86-mingw32
36
-
37
- DEPENDENCIES
38
- bcrypt!
39
- rake-compiler (~> 0.9.2)
40
- rdoc (~> 3.12)
41
- rspec (>= 3)
42
-
43
- BUNDLED WITH
44
- 1.16.1
data/Rakefile DELETED
@@ -1,97 +0,0 @@
1
- require 'rspec/core/rake_task'
2
- require 'rubygems/package_task'
3
- require 'rake/extensiontask'
4
- require 'rake/javaextensiontask'
5
- require 'rake/clean'
6
- require 'rdoc/task'
7
- require 'benchmark'
8
-
9
- CLEAN.include(
10
- "tmp",
11
- "lib/1.8",
12
- "lib/1.9",
13
- "lib/2.0",
14
- "lib/2.1",
15
- "lib/2.2",
16
- "lib/2.3",
17
- "lib/2.4",
18
- "lib/2.5",
19
- "lib/bcrypt_ext.jar",
20
- "lib/bcrypt_ext.so"
21
- )
22
- CLOBBER.include(
23
- "doc",
24
- "pkg"
25
- )
26
-
27
- GEMSPEC = Gem::Specification.load("bcrypt.gemspec")
28
-
29
- task :default => [:compile, :spec]
30
-
31
- desc "Run all specs"
32
- RSpec::Core::RakeTask.new do |t|
33
- t.pattern = 'spec/**/*_spec.rb'
34
- t.ruby_opts = '-w'
35
- end
36
-
37
- desc "Run all specs, with coverage testing"
38
- RSpec::Core::RakeTask.new(:rcov) do |t|
39
- t.pattern = 'spec/**/*_spec.rb'
40
- t.rcov = true
41
- t.rcov_path = 'doc/coverage'
42
- t.rcov_opts = ['--exclude', 'rspec,diff-lcs,rcov,_spec,_helper']
43
- end
44
-
45
- desc 'Generate RDoc'
46
- RDoc::Task.new do |rdoc|
47
- rdoc.rdoc_dir = 'doc/rdoc'
48
- rdoc.options += GEMSPEC.rdoc_options
49
- rdoc.template = ENV['TEMPLATE'] if ENV['TEMPLATE']
50
- rdoc.rdoc_files.include(*GEMSPEC.extra_rdoc_files)
51
- end
52
-
53
- Gem::PackageTask.new(GEMSPEC) do |pkg|
54
- pkg.need_zip = true
55
- pkg.need_tar = true
56
- end
57
-
58
- if RUBY_PLATFORM =~ /java/
59
- Rake::JavaExtensionTask.new('bcrypt_ext', GEMSPEC) do |ext|
60
- ext.ext_dir = 'ext/jruby'
61
- end
62
- else
63
- Rake::ExtensionTask.new("bcrypt_ext", GEMSPEC) do |ext|
64
- ext.ext_dir = 'ext/mri'
65
- ext.cross_compile = true
66
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
67
- end
68
-
69
- ENV['RUBY_CC_VERSION'].to_s.split(':').each do |ruby_version|
70
- platforms = {
71
- "x86-mingw32" => "i686-w64-mingw32",
72
- "x64-mingw32" => "x86_64-w64-mingw32"
73
- }
74
- platforms.each do |platform, prefix|
75
- task "copy:bcrypt_ext:#{platform}:#{ruby_version}" do |t|
76
- %w[lib tmp/#{platform}/stage/lib].each do |dir|
77
- so_file = "#{dir}/#{ruby_version[/^\d+\.\d+/]}/bcrypt_ext.so"
78
- if File.exists?(so_file)
79
- sh "#{prefix}-strip -S #{so_file}"
80
- end
81
- end
82
- end
83
- end
84
- end
85
- end
86
-
87
- desc "Run a set of benchmarks on the compiled extension."
88
- task :benchmark do
89
- TESTS = 100
90
- TEST_PWD = "this is a test"
91
- require File.expand_path(File.join(File.dirname(__FILE__), "lib", "bcrypt"))
92
- Benchmark.bmbm do |results|
93
- 4.upto(10) do |n|
94
- results.report("cost #{n}:") { TESTS.times { BCrypt::Password.create(TEST_PWD, :cost => n) } }
95
- end
96
- end
97
- end