Mercurial > hg > monetdb-ruby
annotate lib/hasher.rb @ 10:2ebc526bc7dd
Updated copyright.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Fri, 06 Jan 2017 13:16:10 +0100 (2017-01-06) |
parents | aab36be83762 |
children | 6abcfcdb4924 |
rev | line source |
---|---|
0
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
1 # This Source Code Form is subject to the terms of the Mozilla Public |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
2 # License, v. 2.0. If a copy of the MPL was not distributed with this |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
4 # |
10 | 5 # Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. |
0
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
6 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
7 require 'digest/md5' |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
8 require 'digest/sha1' |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
9 require 'digest/sha2' |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
10 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
11 class Hasher |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
12 # Constructor |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
13 # method = "SHA1" or "MD5" |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
14 # pwd = Password |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
15 def initialize(method, pwd) |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
16 if (method.upcase == "SHA1") |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
17 @hashfunc = Digest::SHA1.new |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
18 @hashname = method.upcase |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
19 elsif (method.upcase == "SHA256") |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
20 @hashfunc = Digest::SHA256.new |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
21 @hashname = method.upcase |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
22 elsif (method.upcase == "SHA384") |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
23 @hashfunc = Digest::SHA384.new |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
24 @hashname = method.upcase |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
25 elsif (method.upcase == "SHA512") |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
26 @hashfunc = Digest::SHA512.new |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
27 @hashname = method.upcase |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
28 else |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
29 # default to MD5 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
30 @hashfunc = Digest::MD5.new |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
31 @hashname = "MD5" |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
32 end |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
33 @pwd = pwd |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
34 end |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
35 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
36 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
37 def hashname |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
38 @hashname |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
39 end |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
40 |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
41 # Compute hash code |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
42 def hashsum |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
43 return @hashfunc.hexdigest(@pwd) |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
44 end |
aab36be83762
Created a new repository for the Ruby driver for MonetDB.
Sjoerd Mullender <sjoerd@acm.org>
parents:
diff
changeset
|
45 end |