module FunWith::Files::DigestMethods
Public Instance Methods
digest( digest_class = Digest::MD5 )
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 34 def digest( digest_class = Digest::MD5 ) self.file? ? digest_class.hexdigest( self.read ) : "" end
md5()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 6 def md5 digest( Digest::MD5 ) end
sha1()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 10 def sha1 digest( Digest::SHA1 ) end
sha2()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 14 def sha2 digest( Digest::SHA2 ) end
sha224()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 18 def sha224 digest( Digest::SHA224 ) end
sha256()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 22 def sha256 digest( Digest::SHA256 ) end
sha384()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 26 def sha384 digest( Digest::SHA384 ) end
sha512()
click to toggle source
# File lib/fun_with/files/digest_methods.rb, line 30 def sha512 digest( Digest::SHA512 ) end
valid_digest?( opts )
click to toggle source
Takes any of the above-named digest functions, determines whether the file matches a given digest string.
Multiple digests can be given simultaneously. All must pass.
TODO: how to get around the :md6 problem? That is, where the user is sending the wrong key, and hence not getting false back
# File lib/fun_with/files/digest_methods.rb, line 45 def valid_digest?( opts ) for method, digest in opts if DIGEST_METHODS.include?( method ) return false unless self.send( method ) == digest end end return true end