Class: OpenPGP::Digest
- Inherits:
-
Object
show all
- Defined in:
- lib/openpgp/digest.rb,
lib/openpgp/digest/md5.rb,
lib/openpgp/digest/sha1.rb,
lib/openpgp/digest/sha2.rb,
lib/openpgp/digest/rmd160.rb
Overview
OpenPGP message digest algorithm.
Defined Under Namespace
Classes: MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512
Constant Summary
collapse
- DEFAULT =
SHA1
Class Method Summary
collapse
Class Method Details
.algorithm ⇒ Object
37
38
39
|
# File 'lib/openpgp/digest.rb', line 37
def self.algorithm
name.split('::').last.to_sym unless self == Digest
end
|
.digest(data) ⇒ Object
55
56
57
58
|
# File 'lib/openpgp/digest.rb', line 55
def self.digest(data)
require 'digest' unless defined?(::Digest)
::Digest.const_get(algorithm).digest(data)
end
|
.for(identifier) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/openpgp/digest.rb', line 17
def self.for(identifier)
case identifier
when Symbol then const_get(identifier.to_s.upcase)
when String then const_get(identifier.upcase.to_sym)
when 1 then const_get(:MD5)
when 2 then const_get(:SHA1)
when 3 then const_get(:RIPEMD160)
when 8 then const_get(:SHA256)
when 9 then const_get(:SHA384)
when 10 then const_get(:SHA512)
when 11 then const_get(:SHA224)
end
end
|
.hexdigest(data) ⇒ Object
50
51
52
53
|
# File 'lib/openpgp/digest.rb', line 50
def self.hexdigest(data)
require 'digest' unless defined?(::Digest)
::Digest.const_get(algorithm).hexdigest(data).upcase
end
|
.hexsize ⇒ Object
41
42
43
|
# File 'lib/openpgp/digest.rb', line 41
def self.hexsize
size * 2
end
|
.identifier ⇒ Object
33
34
35
|
# File 'lib/openpgp/digest.rb', line 33
def self.identifier
const_get(:IDENTIFIER)
end
|
.size ⇒ Object
45
46
47
48
|
# File 'lib/openpgp/digest.rb', line 45
def self.size
require 'digest' unless defined?(::Digest)
::Digest.const_get(algorithm).new.digest_length
end
|
.to_i ⇒ Object
31
|
# File 'lib/openpgp/digest.rb', line 31
def self.to_i() identifier end
|