Class: KerberosAuthenticator::Krb5::Data

Inherits:
FFI::ManagedStruct
  • Object
show all
Defined in:
lib/kerberos_authenticator/krb5/data.rb

Overview

Generic Kerberos library data structure.

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pointer = nil) ⇒ Data

Allocates and zeroes a new krb5_data struct or cast some existing memory to one.

Parameters:

  • pointer (Pointer) (defaults to: nil)

    a pointer to existing memory to cast to a krb5_data struct

See Also:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/kerberos_authenticator/krb5/data.rb', line 13

def initialize(pointer = nil)
  unless pointer
    pointer = FFI::MemoryPointer.new :char, self.class.size

    # HACK: AutoPointer won't accept a MemoryPointer, only a Pointer
    pointer.autorelease = false
    pointer = FFI::Pointer.new(pointer)
  end

  super(pointer)
end

Class Method Details

.release(pointer) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Frees the contents of a Data struct



35
36
37
# File 'lib/kerberos_authenticator/krb5/data.rb', line 35

def self.release(pointer)
  Krb5.free_data_contents(Context.context.ptr, pointer)
end

Instance Method Details

#read_stringString

Reads the data into a string.

Returns:

  • (String)


27
28
29
30
# File 'lib/kerberos_authenticator/krb5/data.rb', line 27

def read_string
  return '' if self[:length].zero?
  self[:data_ptr].read_bytes(self[:length])
end