class Tanker::Core::EncryptionSession
Public Class Methods
new(csession)
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 8 def initialize(csession) @csession = csession csession_addr = @csession.address ObjectSpace.define_finalizer(@csession) do |_| CTanker.tanker_encryption_session_close(FFI::Pointer.new(:void, csession_addr)).get end end
Public Instance Methods
encrypt_common(data)
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 33 def encrypt_common(data) inbuf = FFI::MemoryPointer.from_string(data) encrypted_size = CTanker.tanker_encryption_session_encrypted_size data.bytesize outbuf = FFI::MemoryPointer.new(:char, encrypted_size) CTanker.tanker_encryption_session_encrypt(@csession, outbuf, inbuf, data.bytesize).get outbuf.read_string encrypted_size end
encrypt_data(data)
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 16 def encrypt_data(data) unless data.is_a?(String) raise TypeError, "expected data to be an ASCII-8BIT binary String, but got a #{data.class}" end unless data.encoding == Encoding::ASCII_8BIT raise ArgumentError, "expected data to be an ASCII-8BIT binary String, but it was #{data.encoding} encoded" end encrypt_common(data) end
encrypt_stream(stream)
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 44 def encrypt_stream(stream) Stream.do_stream_action(stream) { |cb| CTanker.tanker_encryption_session_stream_encrypt(@csession, cb, nil) } end
encrypt_utf8(str)
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 27 def encrypt_utf8(str) ASSERT_UTF8.call(str) encrypt_common str end
resource_id()
click to toggle source
# File lib/tanker/core/encryption_session.rb, line 48 def resource_id CTanker.tanker_encryption_session_get_resource_id(@csession).get_string end