rubycas-server 0.7.1.1 → 1.0
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/CHANGELOG +292 -0
- data/Gemfile +3 -0
- data/LICENSE +26 -0
- data/README.md +36 -0
- data/Rakefile +0 -3
- data/bin/rubycas-server +24 -19
- data/lib/casserver.rb +7 -110
- data/lib/casserver/authenticators/active_directory_ldap.rb +8 -0
- data/lib/casserver/authenticators/active_resource.rb +125 -0
- data/lib/casserver/authenticators/authlogic_crypto_providers/aes256.rb +43 -0
- data/lib/casserver/authenticators/authlogic_crypto_providers/bcrypt.rb +92 -0
- data/lib/casserver/authenticators/authlogic_crypto_providers/md5.rb +34 -0
- data/lib/casserver/authenticators/authlogic_crypto_providers/sha1.rb +59 -0
- data/lib/casserver/authenticators/authlogic_crypto_providers/sha512.rb +50 -0
- data/lib/casserver/authenticators/base.rb +30 -11
- data/lib/casserver/authenticators/client_certificate.rb +7 -6
- data/lib/casserver/authenticators/google.rb +13 -9
- data/lib/casserver/authenticators/ldap.rb +37 -28
- data/lib/casserver/authenticators/ntlm.rb +9 -9
- data/lib/casserver/authenticators/open_id.rb +3 -3
- data/lib/casserver/authenticators/sql.rb +65 -34
- data/lib/casserver/authenticators/sql_authlogic.rb +93 -0
- data/lib/casserver/authenticators/sql_encrypted.rb +44 -44
- data/lib/casserver/authenticators/sql_md5.rb +2 -2
- data/lib/casserver/authenticators/sql_rest_auth.rb +82 -0
- data/lib/casserver/authenticators/test.rb +10 -7
- data/lib/casserver/cas.rb +94 -94
- data/lib/casserver/localization.rb +91 -0
- data/lib/casserver/model.rb +270 -0
- data/lib/casserver/server.rb +745 -0
- data/lib/casserver/utils.rb +9 -7
- data/lib/casserver/views/_login_form.erb +42 -0
- data/lib/casserver/views/layout.erb +18 -0
- data/lib/casserver/views/login.erb +30 -0
- data/lib/casserver/views/proxy.builder +12 -0
- data/lib/casserver/views/proxy_validate.builder +25 -0
- data/lib/casserver/views/service_validate.builder +18 -0
- data/lib/casserver/views/validate.erb +2 -0
- data/po/de_DE/rubycas-server.po +127 -0
- data/po/es_ES/rubycas-server.po +123 -0
- data/po/fr_FR/rubycas-server.po +128 -0
- data/po/ja_JP/rubycas-server.po +126 -0
- data/po/pl_PL/rubycas-server.po +123 -0
- data/po/pt_BR/rubycas-server.po +123 -0
- data/po/ru_RU/rubycas-server.po +118 -0
- data/po/rubycas-server.pot +112 -0
- data/po/zh_CN/rubycas-server.po +113 -0
- data/po/zh_TW/rubycas-server.po +113 -0
- data/public/themes/cas.css +121 -0
- data/{lib → public}/themes/notice.png +0 -0
- data/{lib → public}/themes/ok.png +0 -0
- data/{lib → public}/themes/simple/bg.png +0 -0
- data/public/themes/simple/favicon.png +0 -0
- data/{lib → public}/themes/simple/login_box_bg.png +0 -0
- data/{lib → public}/themes/simple/logo.png +0 -0
- data/public/themes/simple/theme.css +28 -0
- data/{lib → public}/themes/urbacon/bg.png +0 -0
- data/{lib → public}/themes/urbacon/login_box_bg.png +0 -0
- data/{lib → public}/themes/urbacon/logo.png +0 -0
- data/public/themes/urbacon/theme.css +33 -0
- data/{lib → public}/themes/warning.png +0 -0
- data/resources/init.d.sh +1 -1
- data/rubycas-server.gemspec +57 -0
- data/setup.rb +4 -4
- data/spec/alt_config.yml +50 -0
- data/spec/authenticators/active_resource_spec.rb +109 -0
- data/spec/authenticators/ldap_spec.rb +53 -0
- data/spec/casserver_spec.rb +149 -0
- data/spec/default_config.yml +50 -0
- data/spec/model_spec.rb +42 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +88 -0
- data/spec/utils_spec.rb +53 -0
- data/tasks/bundler.rake +4 -0
- data/tasks/db/migrate.rake +12 -0
- data/tasks/localization.rake +13 -0
- data/tasks/spec.rake +10 -0
- metadata +294 -91
- data/CHANGELOG.txt +0 -1
- data/History.txt +0 -252
- data/LICENSE.txt +0 -504
- data/Manifest.txt +0 -72
- data/PostInstall.txt +0 -3
- data/README.txt +0 -25
- data/bin/rubycas-server-ctl +0 -22
- data/config.example.yml +0 -442
- data/config/hoe.rb +0 -76
- data/config/requirements.rb +0 -15
- data/custom_views.example.rb +0 -11
- data/lib/casserver/conf.rb +0 -112
- data/lib/casserver/controllers.rb +0 -452
- data/lib/casserver/environment.rb +0 -30
- data/lib/casserver/models.rb +0 -218
- data/lib/casserver/postambles.rb +0 -174
- data/lib/casserver/version.rb +0 -9
- data/lib/casserver/views.rb +0 -243
- data/lib/rubycas-server.rb +0 -1
- data/lib/rubycas-server/version.rb +0 -1
- data/lib/themes/cas.css +0 -121
- data/lib/themes/simple/theme.css +0 -28
- data/lib/themes/urbacon/theme.css +0 -33
- data/misc/basic_cas_single_signon_mechanism_diagram.png +0 -0
- data/misc/basic_cas_single_signon_mechanism_diagram.svg +0 -652
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/script/txt2html +0 -82
- data/tasks/deployment.rake +0 -34
- data/tasks/environment.rake +0 -7
- data/tasks/website.rake +0 -17
- data/vendor/isaac_0.9.1/LICENSE +0 -26
- data/vendor/isaac_0.9.1/README +0 -78
- data/vendor/isaac_0.9.1/TODO +0 -3
- data/vendor/isaac_0.9.1/VERSIONS +0 -3
- data/vendor/isaac_0.9.1/crypt/ISAAC.rb +0 -171
- data/vendor/isaac_0.9.1/isaac.gemspec +0 -39
- data/vendor/isaac_0.9.1/setup.rb +0 -596
- data/vendor/isaac_0.9.1/test/TC_ISAAC.rb +0 -76
- data/website/index.html +0 -40
- data/website/index.txt +0 -3
- data/website/javascripts/rounded_corners_lite.inc.js +0 -285
- data/website/stylesheets/screen.css +0 -138
- data/website/template.html.erb +0 -40
data/script/console
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# File: script/console
|
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
4
|
-
|
|
5
|
-
libs = " -r irb/completion"
|
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/rubycas-server.rb'}"
|
|
9
|
-
puts "Loading rubycas-server gem"
|
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
-
|
|
4
|
-
begin
|
|
5
|
-
require 'rubigen'
|
|
6
|
-
rescue LoadError
|
|
7
|
-
require 'rubygems'
|
|
8
|
-
require 'rubigen'
|
|
9
|
-
end
|
|
10
|
-
require 'rubigen/scripts/destroy'
|
|
11
|
-
|
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
|
3
|
-
|
|
4
|
-
begin
|
|
5
|
-
require 'rubigen'
|
|
6
|
-
rescue LoadError
|
|
7
|
-
require 'rubygems'
|
|
8
|
-
require 'rubigen'
|
|
9
|
-
end
|
|
10
|
-
require 'rubigen/scripts/generate'
|
|
11
|
-
|
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
GEM_NAME = 'rubycas-server' # what ppl will type to install your gem
|
|
4
|
-
RUBYFORGE_PROJECT = 'rubycas-server'
|
|
5
|
-
|
|
6
|
-
require 'rubygems'
|
|
7
|
-
begin
|
|
8
|
-
require 'newgem'
|
|
9
|
-
require 'rubyforge'
|
|
10
|
-
rescue LoadError
|
|
11
|
-
puts "\n\nGenerating the website requires the newgem RubyGem"
|
|
12
|
-
puts "Install: gem install newgem\n\n"
|
|
13
|
-
exit(1)
|
|
14
|
-
end
|
|
15
|
-
require 'redcloth'
|
|
16
|
-
require 'syntax/convertors/html'
|
|
17
|
-
require 'erb'
|
|
18
|
-
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
|
19
|
-
|
|
20
|
-
version = CASServer::VERSION::STRING
|
|
21
|
-
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
|
22
|
-
|
|
23
|
-
def rubyforge_project_id
|
|
24
|
-
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class Fixnum
|
|
28
|
-
def ordinal
|
|
29
|
-
# teens
|
|
30
|
-
return 'th' if (10..19).include?(self % 100)
|
|
31
|
-
# others
|
|
32
|
-
case self % 10
|
|
33
|
-
when 1: return 'st'
|
|
34
|
-
when 2: return 'nd'
|
|
35
|
-
when 3: return 'rd'
|
|
36
|
-
else return 'th'
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
class Time
|
|
42
|
-
def pretty
|
|
43
|
-
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def convert_syntax(syntax, source)
|
|
48
|
-
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
if ARGV.length >= 1
|
|
52
|
-
src, template = ARGV
|
|
53
|
-
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
|
54
|
-
else
|
|
55
|
-
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
|
56
|
-
exit!
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
template = ERB.new(File.open(template).read)
|
|
60
|
-
|
|
61
|
-
title = nil
|
|
62
|
-
body = nil
|
|
63
|
-
File.open(src) do |fsrc|
|
|
64
|
-
title_text = fsrc.readline
|
|
65
|
-
body_text_template = fsrc.read
|
|
66
|
-
body_text = ERB.new(body_text_template).result(binding)
|
|
67
|
-
syntax_items = []
|
|
68
|
-
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
|
69
|
-
ident = syntax_items.length
|
|
70
|
-
element, syntax, source = $1, $2, $3
|
|
71
|
-
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
|
72
|
-
"syntax-temp-#{ident}"
|
|
73
|
-
}
|
|
74
|
-
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
|
75
|
-
body = RedCloth.new(body_text).to_html
|
|
76
|
-
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
|
77
|
-
end
|
|
78
|
-
stat = File.stat(src)
|
|
79
|
-
created = stat.ctime
|
|
80
|
-
modified = stat.mtime
|
|
81
|
-
|
|
82
|
-
$stdout << template.result(binding)
|
data/tasks/deployment.rake
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
desc 'Release the website and new gem version'
|
|
2
|
-
task :deploy => [:check_version, :website, :release] do
|
|
3
|
-
puts "Remember to create SVN tag:"
|
|
4
|
-
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
|
5
|
-
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
|
6
|
-
puts "Suggested comment:"
|
|
7
|
-
puts "Tagging release #{CHANGES}"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
|
11
|
-
task :local_deploy => [:website_generate, :install_gem]
|
|
12
|
-
|
|
13
|
-
task :check_version do
|
|
14
|
-
unless ENV['VERSION']
|
|
15
|
-
puts 'Must pass a VERSION=x.y.z release version'
|
|
16
|
-
exit
|
|
17
|
-
end
|
|
18
|
-
unless ENV['VERSION'] == VERS
|
|
19
|
-
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
|
20
|
-
exit
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
|
25
|
-
task :install_gem_no_doc => [:clean, :package] do
|
|
26
|
-
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
namespace :manifest do
|
|
30
|
-
desc 'Recreate Manifest.txt to include ALL files'
|
|
31
|
-
task :refresh do
|
|
32
|
-
`rake check_manifest | patch -p0 > Manifest.txt`
|
|
33
|
-
end
|
|
34
|
-
end
|
data/tasks/environment.rake
DELETED
data/tasks/website.rake
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
desc 'Generate website files'
|
|
2
|
-
task :website_generate => :ruby_env do
|
|
3
|
-
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
|
4
|
-
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
desc 'Upload website files to rubyforge'
|
|
9
|
-
task :website_upload do
|
|
10
|
-
host = "#{rubyforge_username}@rubyforge.org"
|
|
11
|
-
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
|
12
|
-
local_dir = 'website'
|
|
13
|
-
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
desc 'Generate and upload website files'
|
|
17
|
-
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/vendor/isaac_0.9.1/LICENSE
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2004 - 2005 Kirk Haines (khaines@enigo.com)
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
For details about the ISAAC algorithm itself, see:
|
|
15
|
-
|
|
16
|
-
http://burtleburtle.net/bob/rand/isaac.html
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
20
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
21
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
22
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
23
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
24
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
25
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
-
|
data/vendor/isaac_0.9.1/README
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Crypt::ISAAC README
|
|
2
|
-
============
|
|
3
|
-
|
|
4
|
-
ISAAC is a cryptographically secure PRNG for generating high quality random
|
|
5
|
-
numbers. Detailed information about the algorithm can be found at:
|
|
6
|
-
|
|
7
|
-
http://burtleburtle.net/bob/rand/isaac.html
|
|
8
|
-
|
|
9
|
-
This is a pure Ruby implementation of the algorithm. It is reasonably fast for
|
|
10
|
-
a pure Ruby implementation. On an 800Mhz PIII computer running Ruby 1.8.2,
|
|
11
|
-
and while the machine is also serving as general desktop, the library seems to
|
|
12
|
-
consistently generate between 15000 and 16000 random numbers per second.
|
|
13
|
-
|
|
14
|
-
Ruby uses the Mersenne Twister as its PRNG, and while this the Twister is
|
|
15
|
-
a fast PRNG that produces highly random numbers, it is not strong for
|
|
16
|
-
cryptographic purposes, nor is it suitable when one needs multiple
|
|
17
|
-
independent streams of random numbers. Crypt::ISAAC is suitable for either
|
|
18
|
-
purpose.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Requirements
|
|
22
|
-
------------
|
|
23
|
-
|
|
24
|
-
* Ruby 1.8 (should also run on 1.6.x)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Install
|
|
28
|
-
-------
|
|
29
|
-
|
|
30
|
-
If you have never installed Crypt::ISAAC, you may run the testsuite
|
|
31
|
-
to confirm that it works with:
|
|
32
|
-
|
|
33
|
-
# ruby setup.rb test
|
|
34
|
-
|
|
35
|
-
If you already have a version of Crypt::ISAAC installed, but want to
|
|
36
|
-
confirm this one before installing, run the test suite manually as
|
|
37
|
-
follows:
|
|
38
|
-
|
|
39
|
-
# ruby test/TC_ISAAC.rb local
|
|
40
|
-
|
|
41
|
-
When you are ready to install Crypt::ISAAC, type:
|
|
42
|
-
|
|
43
|
-
# ruby setup.rb install
|
|
44
|
-
|
|
45
|
-
This one step will install Crypt::ISAAC in your Ruby SITELIB. To test
|
|
46
|
-
the library after installation:
|
|
47
|
-
|
|
48
|
-
# ruby setup.rb test
|
|
49
|
-
|
|
50
|
-
Usage
|
|
51
|
-
-----
|
|
52
|
-
|
|
53
|
-
require 'crypt/ISAAC'
|
|
54
|
-
|
|
55
|
-
rng = Crypt::ISAAC.new
|
|
56
|
-
|
|
57
|
-
r1 = rng.rand() # returns a floating point between 0 and 1
|
|
58
|
-
r2 = rnd.rand(1000) # returns an integer between 0 and 999
|
|
59
|
-
|
|
60
|
-
rand() should work identically to the Kernel.rand().
|
|
61
|
-
|
|
62
|
-
Enjoy it. Let me know if you find anything that can be improved or that
|
|
63
|
-
needs to be fixed.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
License
|
|
67
|
-
-------
|
|
68
|
-
|
|
69
|
-
The Crypt::ISAAC library is licensed with an MIT style licence.
|
|
70
|
-
See the LICENSE file for details. As for the ISAAC algorithm itself,
|
|
71
|
-
see:
|
|
72
|
-
|
|
73
|
-
http://burtleburtle.net/bob/rand/isaac.html
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
Kirk Haines
|
|
78
|
-
khaines@enigo.com
|
data/vendor/isaac_0.9.1/TODO
DELETED
data/vendor/isaac_0.9.1/VERSIONS
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
module Crypt
|
|
2
|
-
|
|
3
|
-
# ISAAC is a fast, strong random number generator. Details on the
|
|
4
|
-
# algorithm can be found here: http://burtleburtle.net/bob/rand/isaac.html
|
|
5
|
-
# This provides a consistent and capable algorithm for producing
|
|
6
|
-
# independent streams of quality random numbers.
|
|
7
|
-
|
|
8
|
-
class ISAAC
|
|
9
|
-
|
|
10
|
-
attr_accessor :randrsl, :randcnt
|
|
11
|
-
attr_accessor :mm, :aa, :bb, :cc
|
|
12
|
-
|
|
13
|
-
# When a Crypt::ISAAC object is created, it needs to be seeded for
|
|
14
|
-
# random number generation. If the system has a /dev/urandom file,
|
|
15
|
-
# that will be used to do the seeding by default. If false is explictly
|
|
16
|
-
# passed when creating the object, it will instead use /dev/random to
|
|
17
|
-
# generate its seeds. Be warned that this may make for SLOW
|
|
18
|
-
# initialization.
|
|
19
|
-
# If the requested source (/dev/urandom or /dev/random) do not exist,
|
|
20
|
-
# the system will fall back to a simplistic initialization mechanism
|
|
21
|
-
# using the builtin Mersenne Twister PRNG.
|
|
22
|
-
|
|
23
|
-
def initialize(noblock = true)
|
|
24
|
-
@mm = []
|
|
25
|
-
@randrsl = []
|
|
26
|
-
# Best initialization of the generator would be by pulling
|
|
27
|
-
# numbers from /dev/random.
|
|
28
|
-
rnd_source = noblock ? '/dev/urandom' : '/dev/random'
|
|
29
|
-
if (FileTest.exist? rnd_source)
|
|
30
|
-
File.open(rnd_source,'r') do |r|
|
|
31
|
-
256.times do |t|
|
|
32
|
-
z = r.read(4)
|
|
33
|
-
x = z.unpack('V')[0]
|
|
34
|
-
@randrsl[t] = x
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
else
|
|
38
|
-
# If urandom isn't available, the standard Ruby PRNG makes an
|
|
39
|
-
# adequate fallback.
|
|
40
|
-
256.times do |t|
|
|
41
|
-
@randrsl[t] = Kernel.rand(4294967295)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
randinit(true)
|
|
45
|
-
nil
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Works just like the standard rand() function. If called with an
|
|
49
|
-
# integer argument, rand() will return positive random number in
|
|
50
|
-
# the range of 0 to (argument - 1). If called without an integer
|
|
51
|
-
# argument, rand() returns a positive floating point number less than 1.
|
|
52
|
-
|
|
53
|
-
def rand(*num)
|
|
54
|
-
if (@randcnt == 1)
|
|
55
|
-
isaac
|
|
56
|
-
@randcnt = 256
|
|
57
|
-
end
|
|
58
|
-
@randcnt -= 1
|
|
59
|
-
if num[0].to_i > 0
|
|
60
|
-
@randrsl[@randcnt].modulo(num[0])
|
|
61
|
-
else
|
|
62
|
-
".#{@randrsl[@randcnt]}".to_f
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def isaac
|
|
67
|
-
i = 0
|
|
68
|
-
x = 0
|
|
69
|
-
y = 0
|
|
70
|
-
|
|
71
|
-
@cc += 1
|
|
72
|
-
@bb += @cc
|
|
73
|
-
@bb & 0xffffffff
|
|
74
|
-
|
|
75
|
-
while (i < 256) do
|
|
76
|
-
x = @mm[i]
|
|
77
|
-
@aa = (@mm[(i + 128) & 255] + (@aa^(@aa << 13)) ) & 0xffffffff
|
|
78
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
|
79
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
|
80
|
-
i += 1
|
|
81
|
-
|
|
82
|
-
x = @mm[i]
|
|
83
|
-
@aa = (@mm[(i+128)&255] + (@aa^(0x03ffffff & (@aa >> 6))) ) & 0xffffffff
|
|
84
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
|
85
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
|
86
|
-
i += 1
|
|
87
|
-
|
|
88
|
-
x = @mm[i]
|
|
89
|
-
@aa = (@mm[(i + 128)&255] + (@aa^(@aa << 2)) ) & 0xffffffff
|
|
90
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
|
91
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
|
92
|
-
i += 1
|
|
93
|
-
|
|
94
|
-
x = @mm[i]
|
|
95
|
-
@aa = (@mm[(i+128)&255] + (@aa^(0x0000ffff & (@aa >> 16))) ) & 0xffffffff
|
|
96
|
-
@mm[i] = y = (@mm[(x>>2)&255] + @aa + @bb ) & 0xffffffff
|
|
97
|
-
@randrsl[i] = @bb = (@mm[(y>>10)&255] + x ) & 0xffffffff
|
|
98
|
-
i += 1
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def randinit(flag)
|
|
103
|
-
i = 0
|
|
104
|
-
a = 0
|
|
105
|
-
b = 0
|
|
106
|
-
c = 0
|
|
107
|
-
d = 0
|
|
108
|
-
e = 0
|
|
109
|
-
f = 0
|
|
110
|
-
g = 0
|
|
111
|
-
@aa = @bb = @cc = 0
|
|
112
|
-
a = b = c = d = e = f = g = h = 0x9e3779b9
|
|
113
|
-
|
|
114
|
-
while (i < 4) do
|
|
115
|
-
a ^= b<<1; d += a; b += c
|
|
116
|
-
b ^= 0x3fffffff & (c>>2); e += b; c += d
|
|
117
|
-
c ^= d << 8; f += c; d += e
|
|
118
|
-
d ^= 0x0000ffff & (e >> 16); g += d; e += f
|
|
119
|
-
e ^= f << 10; h += e; f += g
|
|
120
|
-
f ^= 0x0fffffff & (g >> 4); a += f; g += h
|
|
121
|
-
g ^= h << 8; b += g; h += a
|
|
122
|
-
h ^= 0x007fffff & (a >> 9); c += h; a += b
|
|
123
|
-
i += 1
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
i = 0
|
|
127
|
-
while (i < 256) do
|
|
128
|
-
if (flag)
|
|
129
|
-
a+=@randrsl[i ].to_i; b+=@randrsl[i+1].to_i;
|
|
130
|
-
c+=@randrsl[i+2]; d+=@randrsl[i+3];
|
|
131
|
-
e+=@randrsl[i+4]; f+=@randrsl[i+5];
|
|
132
|
-
g+=@randrsl[i+6]; h+=@randrsl[i+7];
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
a^=b<<11; d+=a; b+=c;
|
|
136
|
-
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
|
137
|
-
c^=d<<8; f+=c; d+=e;
|
|
138
|
-
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
|
139
|
-
e^=f<<10; h+=e; f+=g;
|
|
140
|
-
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
|
141
|
-
g^=h<<8; b+=g; h+=a;
|
|
142
|
-
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
|
143
|
-
@mm[i]=a;@mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
|
144
|
-
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
|
145
|
-
i += 8
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
if flag
|
|
149
|
-
i = 0
|
|
150
|
-
while (i < 256)
|
|
151
|
-
a+=@mm[i ]; b+=@mm[i+1]; c+=@mm[i+2]; d+=@mm[i+3];
|
|
152
|
-
e+=@mm[i+4]; f+=@mm[i+5]; g+=@mm[i+6]; h+=@mm[i+7];
|
|
153
|
-
a^=b<<11; d+=a; b+=c;
|
|
154
|
-
b^=0x3fffffff & (c>>2); e+=b; c+=d;
|
|
155
|
-
c^=d<<8; f+=c; d+=e;
|
|
156
|
-
d^=0x0000ffff & (e>>16); g+=d; e+=f;
|
|
157
|
-
e^=f<<10; h+=e; f+=g;
|
|
158
|
-
f^=0x0fffffff & (g>>4); a+=f; g+=h;
|
|
159
|
-
g^=h<<8; b+=g; h+=a;
|
|
160
|
-
h^=0x007fffff & (a>>9); c+=h; a+=b;
|
|
161
|
-
@mm[i ]=a; @mm[i+1]=b; @mm[i+2]=c; @mm[i+3]=d;
|
|
162
|
-
@mm[i+4]=e; @mm[i+5]=f; @mm[i+6]=g; @mm[i+7]=h;
|
|
163
|
-
i += 8
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
isaac()
|
|
168
|
-
@randcnt=256; # /* prepare to use the first set of results */
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|