Class: OpenPGP::Digest

Inherits:
Object
  • Object
show all
Defined in:
lib/openpgp/digest.rb,
lib/openpgp/digest/md5.rb,
lib/openpgp/digest/sha2.rb,
lib/openpgp/digest/sha1.rb,
lib/openpgp/digest/rmd160.rb

Overview

OpenPGP message digest algorithm.

See Also:

Direct Known Subclasses

Digest::MD5, Digest::RIPEMD160, Digest::SHA1, Digest::SHA224, Digest::SHA256, Digest::SHA384, Digest::SHA512

Defined Under Namespace

Classes: MD5, RIPEMD160, SHA1, SHA224, SHA256, SHA384, SHA512

Constant Summary

DEFAULT =
SHA1

Class Method Summary (collapse)

Class Method Details

+ (Symbol) algorithm

Returns:

  • (Symbol)


46
47
48
# File 'lib/openpgp/digest.rb', line 46

def self.algorithm
  name.split('::').last.to_sym unless self == Digest
end

+ (String) digest(data)

Parameters:

  • (String) data

Returns:

  • (String)


74
75
76
77
# File 'lib/openpgp/digest.rb', line 74

def self.digest(data)
  require 'digest' unless defined?(::Digest)
  ::Digest.const_get(algorithm).digest(data)
end

+ (Class) for(identifier)

Parameters:

  • (Symbol, String, Integer) identifier

Returns:

  • (Class)


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/openpgp/digest.rb', line 20

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

+ (String) hexdigest(data)

Parameters:

  • (String) data

Returns:

  • (String)


66
67
68
69
# File 'lib/openpgp/digest.rb', line 66

def self.hexdigest(data)
  require 'digest' unless defined?(::Digest)
  ::Digest.const_get(algorithm).hexdigest(data).upcase
end

+ (Integer) hexsize

Returns:

  • (Integer)


52
53
54
# File 'lib/openpgp/digest.rb', line 52

def self.hexsize
  size * 2
end

+ (Integer) identifier

Returns:

  • (Integer)


40
41
42
# File 'lib/openpgp/digest.rb', line 40

def self.identifier
  const_get(:IDENTIFIER)
end

+ (Integer) size

Returns:

  • (Integer)


58
59
60
61
# File 'lib/openpgp/digest.rb', line 58

def self.size
  require 'digest' unless defined?(::Digest)
  ::Digest.const_get(algorithm).new.digest_length
end

+ (Integer) to_i

Returns:

  • (Integer)


36
# File 'lib/openpgp/digest.rb', line 36

def self.to_i() identifier end