class IOP::DigestComputer

Filter class to compute digest of the data being passed through. It can be used with digest computing classes from the standard Ruby Digest:: and OpenSSL::Digest:: modules.

### Use case: generate 1024 bytes of random data and compute and print MD5 hash sum of it.

require 'iop/digest'
require 'iop/securerandom'
( IOP::SecureRandomGenerator.new(1024) | ( d = IOP::DigestComputer.new(Digest::MD5.new)) ).process!
puts d.digest.hexdigest

@since 0.1

Attributes

digest[R]

Returns digest object passed to constructor.

Public Class Methods

new(digest) click to toggle source

Creates class instance.

@param digest computer instance to be fed with data

# File lib/iop/digest.rb, line 33
def initialize(digest)
  @digest = digest
end

Public Instance Methods

process(data = nil) click to toggle source
Calls superclass method IOP::Sink#process
# File lib/iop/digest.rb, line 37
def process(data = nil)
  digest.update(data) unless data.nil?
  super
end