Method: GSSAPI::Simple#wrap_message

Defined in:
lib/gssapi/simple.rb

#wrap_message(msg, encrypt = true) ⇒ String

Wrap a message using gss_wrap. It can either encrypt the message (confidentiality) or simply sign it (integrity).

Parameters:

  • msg (String)

    The message to wrap

  • encrypt (Boolean) (defaults to: true)

    Whether or not to encrypt the message or just sign it. The default is to encrypt.

Returns:

  • (String)

    The wrapped message. It will raise an exception on error

Raises:



167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/gssapi/simple.rb', line 167

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