Class: EzCrypto::CipherWrapper
- Inherits:
-
Object
- Object
- EzCrypto::CipherWrapper
- Defined in:
- lib/ezcrypto.rb
Overview
Abstract Wrapper around OpenSSL’s Cipher object. Extended by Encrypter and Decrypter.
You probably should be using the Key class instead.
Warning! The interface may change.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#final ⇒ Object
Finishes up any last bits of data in the cipher and returns the final result.
-
#gulp(data) ⇒ Object
Processes the entire data string using update and performs a final on it returning the data.
-
#initialize(key, target, mode, algorithm) ⇒ CipherWrapper
constructor
A new instance of CipherWrapper.
- #reset(target = "") ⇒ Object
- #to_target(data) ⇒ Object
-
#update(data) ⇒ Object
Process the givend data with the cipher.
Constructor Details
#initialize(key, target, mode, algorithm) ⇒ CipherWrapper
Returns a new instance of CipherWrapper.
431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/ezcrypto.rb', line 431 def initialize(key,target,mode,algorithm) @cipher = OpenSSL::Cipher::Cipher.new(algorithm) if mode @cipher.encrypt else @cipher.decrypt end @cipher.key=key.raw @cipher.padding=1 @target=target @finished=false end |
Instance Method Details
#<<(data) ⇒ Object
460 461 462 |
# File 'lib/ezcrypto.rb', line 460 def <<(data) update(data) end |
#final ⇒ Object
Finishes up any last bits of data in the cipher and returns the final result.
467 468 469 470 471 |
# File 'lib/ezcrypto.rb', line 467 def final @target<< to_target(@cipher.final) @finished=true @target end |
#gulp(data) ⇒ Object
Processes the entire data string using update and performs a final on it returning the data.
476 477 478 479 480 481 |
# File 'lib/ezcrypto.rb', line 476 def gulp(data) update(data) final # rescue # breakpoint end |
#reset(target = "") ⇒ Object
486 487 488 489 |
# File 'lib/ezcrypto.rb', line 486 def reset(target="") @target=target @finished=false end |
#to_target(data) ⇒ Object
445 446 447 |
# File 'lib/ezcrypto.rb', line 445 def to_target(data) return data end |
#update(data) ⇒ Object
Process the givend data with the cipher.
452 453 454 455 |
# File 'lib/ezcrypto.rb', line 452 def update(data) reset if @finished @target<< to_target(@cipher.update(data)) end |