Class: BlockCipherKit::BaseScheme
- Inherits:
-
Object
- Object
- BlockCipherKit::BaseScheme
show all
- Defined in:
- lib/block_cipher_kit/base_scheme.rb
Instance Method Summary
collapse
-
#decrypt_range(from_ciphertext_io:, range:) ⇒ Object
-
#read_copy_stream_via_cipher(source_io:, cipher:, read_limit: nil, destination_io: nil, finalize_cipher: true, &block_accepting_byte_chunks) ⇒ Object
-
#streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk) ⇒ Object
-
#streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk) ⇒ Object
-
#streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk) ⇒ Object
-
#write_copy_stream_via_cipher(cipher:, destination_io:, source_io: nil, read_limit: nil, &block_accepting_writable_io) ⇒ Object
Instance Method Details
#decrypt_range(from_ciphertext_io:, range:) ⇒ Object
14
15
16
17
18
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 14
def decrypt_range(from_ciphertext_io:, range:)
buf = StringIO.new.binmode
streaming_decrypt_range(from_ciphertext_io: from_ciphertext_io, range: range, into_plaintext_io: buf)
buf.string
end
|
#read_copy_stream_via_cipher(source_io:, cipher:, read_limit: nil, destination_io: nil, finalize_cipher: true, &block_accepting_byte_chunks) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 20
def read_copy_stream_via_cipher(source_io:, cipher:, read_limit: nil, destination_io: nil, finalize_cipher: true, &block_accepting_byte_chunks)
writable = BlockCipherKit::BlockWritable.new(destination_io, &block_accepting_byte_chunks)
cipher_io = BlockCipherKit::CipherIO.new(writable, cipher)
IO.copy_stream(source_io, cipher_io, read_limit)
writable.write(cipher.final) if finalize_cipher
end
|
#streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk) ⇒ Object
2
3
4
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 2
def streaming_decrypt(from_ciphertext_io:, into_plaintext_io: nil, &blk)
raise "Unimplemented"
end
|
#streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk) ⇒ Object
10
11
12
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 10
def streaming_decrypt_range(from_ciphertext_io:, range:, into_plaintext_io: nil, &blk)
raise "Unimplemented"
end
|
#streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk) ⇒ Object
6
7
8
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 6
def streaming_encrypt(into_ciphertext_io:, from_plaintext_io: nil, &blk)
raise "Unimplemented"
end
|
#write_copy_stream_via_cipher(cipher:, destination_io:, source_io: nil, read_limit: nil, &block_accepting_writable_io) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/block_cipher_kit/base_scheme.rb', line 30
def write_copy_stream_via_cipher(cipher:, destination_io:, source_io: nil, read_limit: nil, &block_accepting_writable_io)
w = BlockCipherKit::CipherIO.new(destination_io, cipher)
if !source_io && block_accepting_writable_io && !read_limit
block_accepting_writable_io.call(w)
elsif !source_io && block_accepting_writable_io && read_limit
raise "write_copy_stream_via_cipher cannot enforce read_limit when writing via a block"
elsif source_io && !block_accepting_writable_io
IO.copy_stream(source_io, w, read_limit)
else
raise ArgumentError, "Either source_io: or a block accepting a writable IO must be provided"
end
destination_io.write(cipher.final)
end
|