Line | |
---|
1 | =begin
|
---|
2 | = $RCSfile$ -- Ruby-space predefined Digest subclasses
|
---|
3 |
|
---|
4 | = Info
|
---|
5 | 'OpenSSL for Ruby 2' project
|
---|
6 | Copyright (C) 2002 Michal Rokos <[email protected]>
|
---|
7 | All rights reserved.
|
---|
8 |
|
---|
9 | = Licence
|
---|
10 | This program is licenced under the same licence as Ruby.
|
---|
11 | (See the file 'LICENCE'.)
|
---|
12 |
|
---|
13 | = Version
|
---|
14 | $Id: digest.rb 11708 2007-02-12 23:01:19Z shyouhei $
|
---|
15 | =end
|
---|
16 |
|
---|
17 | ##
|
---|
18 | # Should we care what if somebody require this file directly?
|
---|
19 | #require 'openssl'
|
---|
20 |
|
---|
21 | module OpenSSL
|
---|
22 | module Digest
|
---|
23 |
|
---|
24 | alg = %w(DSS DSS1 MD2 MD4 MD5 MDC2 RIPEMD160 SHA SHA1)
|
---|
25 | if OPENSSL_VERSION_NUMBER > 0x00908000
|
---|
26 | alg += %w(SHA224 SHA256 SHA384 SHA512)
|
---|
27 | end
|
---|
28 |
|
---|
29 | alg.each{|name|
|
---|
30 | klass = Class.new(Digest){
|
---|
31 | define_method(:initialize){|*data|
|
---|
32 | if data.length > 1
|
---|
33 | raise ArgumentError,
|
---|
34 | "wrong number of arguments (#{data.length} for 1)"
|
---|
35 | end
|
---|
36 | super(name, data.first)
|
---|
37 | }
|
---|
38 | }
|
---|
39 | singleton = (class <<klass; self; end)
|
---|
40 | singleton.class_eval{
|
---|
41 | define_method(:digest){|data| Digest.digest(name, data) }
|
---|
42 | define_method(:hexdigest){|data| Digest.hexdigest(name, data) }
|
---|
43 | }
|
---|
44 | const_set(name, klass)
|
---|
45 | }
|
---|
46 |
|
---|
47 | end # Digest
|
---|
48 | end # OpenSSL
|
---|
49 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.