Class: IOP::DigestComputer
- Inherits:
-
Object
- Object
- IOP::DigestComputer
- 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
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns digest object passed to constructor.
Attributes included from Sink
Attributes included from Feed
Instance Method Summary collapse
-
#initialize(digest) ⇒ DigestComputer
constructor
Creates class instance.
- #process(data = nil) ⇒ Object
Methods included from Sink
Methods included from Feed
Constructor Details
#initialize(digest) ⇒ DigestComputer
Creates class instance.
33 34 35 |
# File 'lib/iop/digest.rb', line 33 def initialize(digest) @digest = digest end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns digest object passed to constructor.
27 28 29 |
# File 'lib/iop/digest.rb', line 27 def digest @digest end |
Instance Method Details
#process(data = nil) ⇒ Object
37 38 39 40 |
# File 'lib/iop/digest.rb', line 37 def process(data = nil) digest.update(data) unless data.nil? super end |