def wrap_message(msg, encrypt = true)
min_stat = FFI::MemoryPointer.new :OM_uint32
conf_req = (encrypt ? 1 : 0)
qop_req = GSSAPI::LibGSSAPI::GSS_C_QOP_DEFAULT
in_buff = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
in_buff.value = msg
conf_state = FFI::MemoryPointer.new :OM_uint32
out_buff = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
maj_stat = GSSAPI::LibGSSAPI.gss_wrap(min_stat, @context, conf_req, qop_req, in_buff.pointer, conf_state, out_buff.pointer)
raise GssApiError.new(maj_stat, min_stat), "Failed to gss_wrap message" if maj_stat != 0
out_buff.value
end