module SecurizeString::DigestMethods::InstanceMethods

Adds instance methods for OpenSSL::Digest support via inclusion of SecurizeString::DigestMethods to a class.

Public Instance Methods

to_digest(digest) click to toggle source

Returns the digest of the byte string as a SecureString using the passed digest from the list of digests in supported_digests.

# File lib/securize_string/digest_methods.rb, line 30
def to_digest(digest)
  digest_obj = DigestFinder.find(digest).new
  return self.class.new( digest_obj.digest(self) )
end
to_md5() click to toggle source

Returns the MD5 of the byte string as a SecureString.

# File lib/securize_string/digest_methods.rb, line 36
def to_md5
  return to_digest('MD5')
end
to_sha1() click to toggle source

Returns the SHA1 of the byte string as SecureString

# File lib/securize_string/digest_methods.rb, line 41
def to_sha1
  return to_digest('SHA-1')
end
to_sha2(length=256) click to toggle source

Returns the SHA2 of the byte string as a SecureString.

By default, this uses the 256 bit SHA2, but the optional arugment allows specification of which bit length to use.

# File lib/securize_string/digest_methods.rb, line 49
def to_sha2(length=256)
  if [224,256,384,512].include?(length)
    digest = "SHA-#{length}"
    return to_digest( digest )
  else
    raise ArgumentError, "Invalid SHA2 length: #{length}"
  end
end
to_sha256() click to toggle source

Returns the SHA2 256 of the data string. See to_sha2.

# File lib/securize_string/digest_methods.rb, line 59
def to_sha256
  return to_sha2(256)
end
to_sha512() click to toggle source

Returns the SHA2 512 of the data string. See to_sha2.

# File lib/securize_string/digest_methods.rb, line 64
def to_sha512
  return to_sha2(512)
end