Class: IOP::DigestComputer

Inherits:
Object
  • Object
show all
Includes:
Feed, Sink
Defined in:
lib/iop/digest.rb

Overview

Filter class to compute digest of the data being passed through. It can be used with digest computing classes from digest and openssl standard Ruby 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

Instance Attribute Summary collapse

Attributes included from Sink

#upstream

Attributes included from Feed

#downstream

Instance Method Summary collapse

Methods included from Sink

#process!

Methods included from Feed

#process!, #|

Constructor Details

#initialize(digest) ⇒ DigestComputer

Creates class instance.

Parameters:

  • digest

    computer instance to be fed with data

Since:

  • 0.1



33
34
35
# File 'lib/iop/digest.rb', line 33

def initialize(digest)
  @digest = digest
end

Instance Attribute Details

#digestObject (readonly)

Returns digest object passed to constructor.

Since:

  • 0.1



27
28
29
# File 'lib/iop/digest.rb', line 27

def digest
  @digest
end

Instance Method Details

#process(data = nil) ⇒ Object

Since:

  • 0.1



37
38
39
40
# File 'lib/iop/digest.rb', line 37

def process(data = nil)
  digest.update(data) unless data.nil?
  super
end