def unwrap_message(msg, encrypted = true)
min_stat = FFI::MemoryPointer.new :OM_uint32
in_buff = GSSAPI::LibGSSAPI::UnManagedGssBufferDesc.new
in_buff.value = msg
out_buff = GSSAPI::LibGSSAPI::ManagedGssBufferDesc.new
conf_state = FFI::MemoryPointer.new :int
conf_state.write_int((encrypted ? 1 : 0))
q_op = FFI::MemoryPointer.new :OM_uint32
q_op.write_int(0)
maj_stat = GSSAPI::LibGSSAPI.gss_unwrap(min_stat, @context, in_buff.pointer, out_buff.pointer, conf_state, q_op)
raise GssApiError.new(maj_stat, min_stat), "Failed to gss_unwrap message" if maj_stat != 0
out_buff.value
end