rubycas-server 0.5.0.186 → 0.5.0.193
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/Manifest.txt +12 -2
- data/vendor/camping-1.5.180/CHANGELOG +99 -0
- data/vendor/camping-1.5.180/COPYING +18 -0
- data/vendor/camping-1.5.180/README +119 -0
- data/vendor/camping-1.5.180/Rakefile +117 -0
- data/vendor/isaac_0.9.1/LICENSE +26 -0
- data/vendor/isaac_0.9.1/README +78 -0
- data/vendor/isaac_0.9.1/TODO +3 -0
- data/vendor/isaac_0.9.1/VERSIONS +3 -0
- data/vendor/isaac_0.9.1/crypt/ISAAC.rb +171 -0
- data/vendor/isaac_0.9.1/isaac.gemspec +39 -0
- data/vendor/isaac_0.9.1/setup.rb +596 -0
- data/vendor/isaac_0.9.1/test/TC_ISAAC.rb +76 -0
- metadata +14 -2
data/Manifest.txt
CHANGED
@@ -36,7 +36,10 @@ lib/themes/warning.png
|
|
36
36
|
resources/init.d.sh
|
37
37
|
setup.rb
|
38
38
|
test/test_casserver.rb
|
39
|
-
|
39
|
+
vendor/camping-1.5.180/CHANGELOG
|
40
|
+
vendor/camping-1.5.180/COPYING
|
41
|
+
vendor/camping-1.5.180/README
|
42
|
+
vendor/camping-1.5.180/Rakefile
|
40
43
|
vendor/camping-1.5.180/lib/camping-unabridged.rb
|
41
44
|
vendor/camping-1.5.180/lib/camping.rb
|
42
45
|
vendor/camping-1.5.180/lib/camping/db.rb
|
@@ -44,4 +47,11 @@ vendor/camping-1.5.180/lib/camping/fastcgi.rb
|
|
44
47
|
vendor/camping-1.5.180/lib/camping/reloader.rb
|
45
48
|
vendor/camping-1.5.180/lib/camping/session.rb
|
46
49
|
vendor/camping-1.5.180/lib/camping/webrick.rb
|
47
|
-
|
50
|
+
vendor/isaac_0.9.1/LICENSE
|
51
|
+
vendor/isaac_0.9.1/README
|
52
|
+
vendor/isaac_0.9.1/TODO
|
53
|
+
vendor/isaac_0.9.1/VERSIONS
|
54
|
+
vendor/isaac_0.9.1/crypt/ISAAC.rb
|
55
|
+
vendor/isaac_0.9.1/isaac.gemspec
|
56
|
+
vendor/isaac_0.9.1/setup.rb
|
57
|
+
vendor/isaac_0.9.1/test/TC_ISAAC.rb
|
@@ -0,0 +1,99 @@
|
|
1
|
+
= 1.5
|
2
|
+
=== 3rd Oct, 2006
|
3
|
+
|
4
|
+
* Camping::Apps stores an array of classes for all loaded apps.
|
5
|
+
* bin/camping can be given a directory. Like: <tt>camping examples/</tt>
|
6
|
+
* Console mode -- thank zimbatm. Use: camping -C yourapp.rb
|
7
|
+
* Call controllers with Camping.method_missing.
|
8
|
+
|
9
|
+
Tepee.get(:Index) #=> (Response)
|
10
|
+
Blog.post(:Delete, id) #=> (Response)
|
11
|
+
|
12
|
+
Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'})
|
13
|
+
#=> #<Blog::Controllers::Login @user=... >
|
14
|
+
|
15
|
+
Blog.get(:Info, :env => {:HTTP_HOST => 'wagon'})
|
16
|
+
#=> #<Blog::Controllers::Info @env={'HTTP_HOST'=>'wagon'} ...>
|
17
|
+
|
18
|
+
* Using \r\n instead of \n on output. FastCGI has these needs.
|
19
|
+
* ActiveRecord no longer required or installed.
|
20
|
+
* If you refer to Models::Base, however, ActiveRecord will be loaded with autoload. (see lib/camping/db.rb)
|
21
|
+
* new Camping::FastCGI.serve which will serve a whole directory of apps
|
22
|
+
(see http://code.whytheluckystiff.net/camping/wiki/TheCampingServer)
|
23
|
+
* ~/.campingrc can contain database connection info if you want your default to be something other than SQLite.
|
24
|
+
|
25
|
+
database:
|
26
|
+
adapter: mysql
|
27
|
+
username: camping
|
28
|
+
socket: /tmp/mysql.sock
|
29
|
+
password: NOFORESTFIRES
|
30
|
+
database: camping
|
31
|
+
|
32
|
+
* controllers are now *ordered*. uses the inherited hook to keep track of all
|
33
|
+
classes created with R. those classes are scanned, in order, when a request is
|
34
|
+
made. any other controllers are handled first. so if you plan on overriding the
|
35
|
+
urls method, be sure to subclass from R().
|
36
|
+
* Console mode will load .irbrc in the working directory, if present.
|
37
|
+
(for example, in my ~/git/balloon directory, i have this in the .irbrc:
|
38
|
+
include Balloon::Models
|
39
|
+
when camping -C balloon.rb gets run, the models all get included in main.)
|
40
|
+
* And, of course, many other bugfixes from myself and the loyal+kind zimbatm...
|
41
|
+
* Markaby updated to 0.5. (See its CHANGELOG.)
|
42
|
+
|
43
|
+
= 1.4.2
|
44
|
+
=== 18th May, 2006
|
45
|
+
|
46
|
+
* Efficient file uploads for multipart/form-data POSTs.
|
47
|
+
* Camping tool now uses Mongrel, if available. If not, sticks with WEBrick.
|
48
|
+
* Multiple apps can be loaded with the camping tool, each mounted according to their file name.
|
49
|
+
|
50
|
+
= 1.4.1
|
51
|
+
=== 3rd May, 2006
|
52
|
+
|
53
|
+
* Streaming HTTP support. If body is IO, will simply pass to the controller. Mongrel, in particular, supports this nicely.
|
54
|
+
|
55
|
+
= 1.4
|
56
|
+
=== 11th April, 2006
|
57
|
+
|
58
|
+
* Moved Camping::Controllers::Base to Camping::Base.
|
59
|
+
* Moved Camping::Controllers::R to Camping::R.
|
60
|
+
* New session library (lib/camping/session.rb).
|
61
|
+
* WEBrick handler (lib/camping/webrick.rb) and Mongrel handler (lib/camping/mongrel.rb).
|
62
|
+
* Helpers#URL, builds a complete URL for a route. Returns a URI object. This way relative links could just return self.URL.path.
|
63
|
+
* Base#initialize takes over some of Base#service's duties.
|
64
|
+
* ENV now available as @env in controllers and views.
|
65
|
+
* Beautiful multi-page docs without frames!
|
66
|
+
|
67
|
+
= 1.3
|
68
|
+
=== 28th January, 2006
|
69
|
+
|
70
|
+
* bin/camping: an application launcher.
|
71
|
+
* <tt>Camping.run(request, response)</tt> now changed to <tt>controller = Camping.run(request, env)</tt>
|
72
|
+
* This means outputting the response is the wrapper/server's job. See bin/camping, you can do a controller.to_s at the least.
|
73
|
+
* <tt>Controllers::Base.env</tt> is the new thread-safe home for <tt>ENV</tt>.
|
74
|
+
* The input hash now works more like Rails params. You can call keys
|
75
|
+
like methods or with symbols or strings.
|
76
|
+
* Queries are now parsed more like PHP/Rails, in that you can denote
|
77
|
+
structure with brackets: post[user]=_why;post[id]=2
|
78
|
+
* Auto-prefix table names, to help prevent name clash.
|
79
|
+
* Helpers.errors_for simple validation.
|
80
|
+
* Lots of empty :href and :action attributes, a bug.
|
81
|
+
* New single-page flipbook RDoc template.
|
82
|
+
|
83
|
+
= 1.2
|
84
|
+
=== 23rd January, 2006
|
85
|
+
|
86
|
+
* Camping.goes allows fresh modules build from all Camping parts.
|
87
|
+
* File uploads now supported (multipart/form-data).
|
88
|
+
* Helpers.R can rebuild routes.
|
89
|
+
* Helpers./ for tracing paths from the root.
|
90
|
+
|
91
|
+
= 1.1
|
92
|
+
=== 19th January, 2006
|
93
|
+
|
94
|
+
* Allowed request and response streams to be passed in, to allow WEBrick and FastCGI support.
|
95
|
+
|
96
|
+
= 1.0
|
97
|
+
=== 17th January, 2006
|
98
|
+
|
99
|
+
* Initial checkin, see announcement at http://redhanded.hobix.com/bits/campingAMicroframework.html.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2006 why the lucky stiff
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,119 @@
|
|
1
|
+
== Camping, a Microframework
|
2
|
+
|
3
|
+
Camping is a web framework which consistently stays at less than 4kb of code.
|
4
|
+
You can probably view the complete source code on a single page. But, you know,
|
5
|
+
it's so small that, if you think about it, what can it really do?
|
6
|
+
|
7
|
+
The idea here is to store a complete fledgling web application in a single file
|
8
|
+
like many small CGIs. But to organize it as a Model-View-Controller application
|
9
|
+
like Rails does. You can then easily move it to Rails once you've got it going.
|
10
|
+
|
11
|
+
== A Camping Skeleton
|
12
|
+
|
13
|
+
A skeletal Camping blog could look like this:
|
14
|
+
|
15
|
+
require 'camping'
|
16
|
+
|
17
|
+
Camping.goes :Blog
|
18
|
+
|
19
|
+
module Blog::Models
|
20
|
+
class Post < Base; belongs_to :user; end
|
21
|
+
class Comment < Base; belongs_to :user; end
|
22
|
+
class User < Base; end
|
23
|
+
end
|
24
|
+
|
25
|
+
module Blog::Controllers
|
26
|
+
class Index < R '/'
|
27
|
+
def get
|
28
|
+
@posts = Post.find :all
|
29
|
+
render :index
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Blog::Views
|
35
|
+
def layout
|
36
|
+
html do
|
37
|
+
body do
|
38
|
+
self << yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def index
|
44
|
+
for post in @posts
|
45
|
+
h1 post.title
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Some things you might have noticed:
|
51
|
+
|
52
|
+
* Camping::Models uses ActiveRecord to do its work. We love ActiveRecord!
|
53
|
+
* Camping::Controllers can be assigned URLs in the class definition. Neat?
|
54
|
+
* Camping::Views describes HTML using pure Ruby. Markup as Ruby, which we
|
55
|
+
call Markaby.
|
56
|
+
* You use Camping::goes to make a copy of the Camping framework under your
|
57
|
+
own module name (in this case: <tt>Blog</tt>.)
|
58
|
+
|
59
|
+
<b>NOTE:</b> Camping auto-prefixes table names. If your class is named
|
60
|
+
<tt>Blog::Models::Post</tt>, your table will be called <b>blog_posts</b>.
|
61
|
+
Since many Camping apps can be attached to a database at once, this helps
|
62
|
+
prevent name clash.
|
63
|
+
|
64
|
+
(If you want to see the full blog example, check out <tt>examples/blog/blog.rb</tt>
|
65
|
+
for the complete code.)
|
66
|
+
|
67
|
+
If you want to write larger applications with Camping, you are encouraged to
|
68
|
+
split the application into distinct parts which can be mounted at URLs on your
|
69
|
+
web server. You might have a blog at /blog and a wiki at /wiki. Each
|
70
|
+
self-contained. But you can certainly share layouts and models by storing them
|
71
|
+
in plain Ruby scripts.
|
72
|
+
|
73
|
+
Interested yet? Okay, okay, one step at a time.
|
74
|
+
|
75
|
+
== Installation
|
76
|
+
|
77
|
+
* <tt>gem install camping</tt>
|
78
|
+
|
79
|
+
Or for the bleeding edge:
|
80
|
+
|
81
|
+
* <tt>gem install camping --source code.whytheluckystiff.net</tt>
|
82
|
+
|
83
|
+
You are encourage to install Camping and SQLite3, since it is a small database
|
84
|
+
which fits perfectly with our compact bylaws, works well with the examples.
|
85
|
+
|
86
|
+
* See http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.
|
87
|
+
|
88
|
+
== Running Camping Apps
|
89
|
+
|
90
|
+
The blog example above and most Camping applications look a lot like CGI scripts.
|
91
|
+
If you run them from the commandline, you'll probably just see a pile of HTML.
|
92
|
+
|
93
|
+
Camping comes with an tool for launching apps from the commandline:
|
94
|
+
|
95
|
+
* Run: <tt>camping blog.rb</tt>
|
96
|
+
* Visit http://localhost:3301/blog/ to use the app.
|
97
|
+
|
98
|
+
== How the Camping Tool Works
|
99
|
+
|
100
|
+
If your application isn't working with the <tt>camping</tt> tool, keep in mind
|
101
|
+
that the tool expects the following conventions to be used:
|
102
|
+
|
103
|
+
1. You must have SQLite3 and SQLite3-ruby installed. (Once again, please see
|
104
|
+
http://code.whytheluckystiff.net/camping/wiki/BeAlertWhenOnSqlite3 for instructions.)
|
105
|
+
2. If your script is called <tt>test.rb</tt>, Camping expects your application to
|
106
|
+
be stored in a module called <tt>Test</tt>. Case is not imporant, though. The
|
107
|
+
module can be called <tt>TeSt</tt> or any other permutation.
|
108
|
+
3. Your script's postamble (anything enclosed in <tt>if __FILE__ == $0</tt>) will be
|
109
|
+
ignored by the tool, since the tool will create an SQLite3 database at
|
110
|
+
<tt>~/.camping.db</tt>. Or, on Windows, <tt>$USER/Application Data/Camping.db</tt>.
|
111
|
+
4. If your application's module has a <tt>create</tt> method, it will be executed before
|
112
|
+
the web server starts up.
|
113
|
+
|
114
|
+
== The Rules of Thumb
|
115
|
+
|
116
|
+
Once you've started writing your own Camping app, I'd highly recommend that you become familiar
|
117
|
+
with the Camping Rules of Thumb which are listed on the wiki:
|
118
|
+
http://code.whytheluckystiff.net/camping/wiki/CampingRulesOfThumb
|
119
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'fileutils'
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
NAME = "camping"
|
10
|
+
REV = File.read(".svn/entries")[/committed-rev="(\d+)"/, 1] rescue nil
|
11
|
+
VERS = ENV['VERSION'] || ("1.5" + (REV ? ".#{REV}" : ""))
|
12
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config', 'test/test.log']
|
13
|
+
RDOC_OPTS = ['--quiet', '--title', "Camping, the Documentation",
|
14
|
+
"--opname", "index.html",
|
15
|
+
"--line-numbers",
|
16
|
+
"--main", "README",
|
17
|
+
"--inline-source"]
|
18
|
+
|
19
|
+
desc "Packages up Camping."
|
20
|
+
task :default => [:package]
|
21
|
+
task :package => [:clean]
|
22
|
+
|
23
|
+
task :doc => [:before_doc, :rdoc, :after_doc]
|
24
|
+
|
25
|
+
task :before_doc do
|
26
|
+
mv "lib/camping.rb", "lib/camping-mural.rb"
|
27
|
+
mv "lib/camping-unabridged.rb", "lib/camping.rb"
|
28
|
+
end
|
29
|
+
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
32
|
+
rdoc.options += RDOC_OPTS
|
33
|
+
rdoc.template = "extras/flipbook_rdoc.rb"
|
34
|
+
rdoc.main = "README"
|
35
|
+
rdoc.title = "Camping, the Documentation"
|
36
|
+
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/camping.rb', 'lib/camping/*.rb']
|
37
|
+
end
|
38
|
+
|
39
|
+
task :after_doc do
|
40
|
+
mv "lib/camping.rb", "lib/camping-unabridged.rb"
|
41
|
+
mv "lib/camping-mural.rb", "lib/camping.rb"
|
42
|
+
cp "extras/Camping.gif", "doc/rdoc/"
|
43
|
+
cp "extras/permalink.gif", "doc/rdoc/"
|
44
|
+
sh %{scp -r doc/rdoc/* #{ENV['USER']}@rubyforge.org:/var/www/gforge-projects/camping/}
|
45
|
+
end
|
46
|
+
|
47
|
+
spec =
|
48
|
+
Gem::Specification.new do |s|
|
49
|
+
s.name = NAME
|
50
|
+
s.version = VERS
|
51
|
+
s.platform = Gem::Platform::RUBY
|
52
|
+
s.has_rdoc = true
|
53
|
+
s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
|
54
|
+
s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)\/', '--exclude', 'lib/camping.rb']
|
55
|
+
s.summary = "minature rails for stay-at-home moms"
|
56
|
+
s.description = s.summary
|
57
|
+
s.author = "why the lucky stiff"
|
58
|
+
s.email = 'why@ruby-lang.org'
|
59
|
+
s.homepage = 'http://code.whytheluckystiff.net/camping/'
|
60
|
+
s.executables = ['camping']
|
61
|
+
|
62
|
+
s.add_dependency('activesupport', '>=1.3.1')
|
63
|
+
s.add_dependency('markaby', '>=0.5')
|
64
|
+
s.add_dependency('metaid')
|
65
|
+
s.required_ruby_version = '>= 1.8.2'
|
66
|
+
|
67
|
+
s.files = %w(COPYING README Rakefile) +
|
68
|
+
Dir.glob("{bin,doc,test,lib,extras}/**/*") +
|
69
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
70
|
+
Dir.glob("examples/**/*.rb") +
|
71
|
+
Dir.glob("tools/*.rb")
|
72
|
+
|
73
|
+
s.require_path = "lib"
|
74
|
+
# s.extensions = FileList["ext/**/extconf.rb"].to_a
|
75
|
+
s.bindir = "bin"
|
76
|
+
end
|
77
|
+
|
78
|
+
omni =
|
79
|
+
Gem::Specification.new do |s|
|
80
|
+
s.name = "camping-omnibus"
|
81
|
+
s.version = VERS
|
82
|
+
s.platform = Gem::Platform::RUBY
|
83
|
+
s.summary = "the camping meta-package for updating ActiveRecord, Mongrel and SQLite3 bindings"
|
84
|
+
s.description = s.summary
|
85
|
+
%w[author email homepage].each { |x| s.__send__("#{x}=", spec.__send__(x)) }
|
86
|
+
|
87
|
+
s.add_dependency('camping', "=#{VERS}")
|
88
|
+
s.add_dependency('activerecord')
|
89
|
+
s.add_dependency('sqlite3-ruby', '>=1.1.0.1')
|
90
|
+
s.add_dependency('mongrel')
|
91
|
+
s.add_dependency('acts_as_versioned')
|
92
|
+
s.add_dependency('RedCloth')
|
93
|
+
end
|
94
|
+
|
95
|
+
Rake::GemPackageTask.new(spec) do |p|
|
96
|
+
p.need_tar = true
|
97
|
+
p.gem_spec = spec
|
98
|
+
end
|
99
|
+
|
100
|
+
Rake::GemPackageTask.new(omni) do |p|
|
101
|
+
p.gem_spec = omni
|
102
|
+
end
|
103
|
+
|
104
|
+
task :install do
|
105
|
+
sh %{rake package}
|
106
|
+
sh %{sudo gem install pkg/#{NAME}-#{VERS}}
|
107
|
+
end
|
108
|
+
|
109
|
+
task :uninstall => [:clean] do
|
110
|
+
sh %{sudo gem uninstall #{NAME}}
|
111
|
+
end
|
112
|
+
|
113
|
+
Rake::TestTask.new(:test) do |t|
|
114
|
+
t.test_files = FileList['test/test_*.rb']
|
115
|
+
# t.warning = true
|
116
|
+
# t.verbose = true
|
117
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
|
@@ -0,0 +1,78 @@
|
|
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
|
@@ -0,0 +1,171 @@
|
|
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
|