Class: Shh::BlowfishSerialiser
- Inherits:
-
Object
- Object
- Shh::BlowfishSerialiser
- Defined in:
- lib/shh/blowfish_serialiser.rb
Instance Method Summary collapse
-
#initialize(serialiser, passphrase) ⇒ BlowfishSerialiser
constructor
A new instance of BlowfishSerialiser.
- #read(io) ⇒ Object
- #write(io, hash) ⇒ Object
Constructor Details
#initialize(serialiser, passphrase) ⇒ BlowfishSerialiser
Returns a new instance of BlowfishSerialiser.
5 6 7 8 |
# File 'lib/shh/blowfish_serialiser.rb', line 5 def initialize serialiser, passphrase @blowfish = ::Crypt::Blowfish.new(passphrase) @serialiser = serialiser end |
Instance Method Details
#read(io) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/shh/blowfish_serialiser.rb', line 10 def read io decrypted_io = StringIO.new while l = io.read(8) do decrypted_io.print @blowfish.decrypt_block(l) end @serialiser.read StringIO.new(decrypted_io.string.gsub("\0",'')) end |
#write(io, hash) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/shh/blowfish_serialiser.rb', line 18 def write io, hash serialised_io = StringIO.new @serialiser.write serialised_io, hash serialised_io.rewind while l = serialised_io.read(8) do while l.size < 8 do l += "\0" end io.print @blowfish.encrypt_block(l) end end |