Class: CZMQ::FFI::Zcertstore

Inherits:
Object
  • Object
show all
Defined in:
lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb

Overview

Note:

This class is 100% generated using zproject.

work with CURVE security certificate stores

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zcertstore

Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.

Parameters:

  • ptr (::FFI::Pointer)
  • finalize (Boolean) (defaults to: true)


24
25
26
27
28
29
30
31
32
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 24

def initialize(ptr, finalize = true)
  @ptr = ptr
  if @ptr.null?
    @ptr = nil # Remove null pointers so we don't have to test for them.
  elsif finalize
    @finalizer = self.class.create_finalizer_for @ptr
    ObjectSpace.define_finalizer self, @finalizer
  end
end

Class Method Details

.__newObject



18
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 18

alias :__new :new

.create_finalizer_for(ptr) ⇒ Proc

Parameters:

  • ptr (::FFI::Pointer)

Returns:

  • (Proc)


35
36
37
38
39
40
41
42
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 35

def self.create_finalizer_for(ptr)
  ptr_ptr = ::FFI::MemoryPointer.new :pointer

  Proc.new do
    ptr_ptr.write_pointer ptr
    ::CZMQ::FFI.zcertstore_destroy ptr_ptr
  end
end

.destructorObject

Note:

WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.

Create a new callback of the following type: Destructor for loader state.

typedef void (zcertstore_destructor) (
    void **self_p);


103
104
105
106
107
108
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 103

def self.destructor
  ::FFI::Function.new :void, [:pointer], blocking: true do |self_p|
    result = yield self_p
    result
  end
end

.loaderObject

Note:

WARNING: If your Ruby code doesn’t retain a reference to the FFI::Function object after passing it to a C function call, it may be garbage collected while C still holds the pointer, potentially resulting in a segmentation fault.

Create a new callback of the following type: Loaders retrieve certificates from an arbitrary source.

typedef void (zcertstore_loader) (
    zcertstore_t *self);


86
87
88
89
90
91
92
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 86

def self.loader
  ::FFI::Function.new :void, [:pointer], blocking: true do |self_|
    self_ = Zcertstore.__new self_, false
    result = yield self_
    result
  end
end

.new(location) ⇒ CZMQ::Zcertstore

Create a new certificate store from a disk directory, loading and indexing all certificates in that location. The directory itself may be absent, and created later, or modified at any time. The certificate store is automatically refreshed on any zcertstore_lookup() call. If the location is specified as NULL, creates a pure-memory store, which you can work with by inserting certificates at runtime.

Parameters:

  • location (String, #to_s, nil)

Returns:

  • (CZMQ::Zcertstore)


118
119
120
121
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 118

def self.new(location)
  ptr = ::CZMQ::FFI.zcertstore_new(location)
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class

Parameters:

  • verbose (Boolean)


223
224
225
226
227
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 223

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zcertstore_test(verbose)
  result
end

Instance Method Details

#__ptr::FFI::Pointer Also known as: to_ptr

Return internal pointer

Returns:

  • (::FFI::Pointer)

Raises:



49
50
51
52
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 49

def __ptr
  raise DestroyedError unless @ptr
  @ptr
end

#__ptr_give_ref::FFI::MemoryPointer

Note:

This detaches the current instance from the native object and thus makes it unusable.

Nullify internal pointer and return pointer pointer.

Returns:

  • (::FFI::MemoryPointer)

    the pointer pointing to a pointer pointing to the native object

Raises:



60
61
62
63
64
65
66
67
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 60

def __ptr_give_ref
  raise DestroyedError unless @ptr
  ptr_ptr = ::FFI::MemoryPointer.new :pointer
  ptr_ptr.write_pointer @ptr
  __undef_finalizer if @finalizer
  @ptr = nil
  ptr_ptr
end

#__undef_finalizervoid

Note:

Only use this if you need to and can guarantee that the native object will be freed by other means.

This method returns an undefined value.

Undefines the finalizer for this object.



72
73
74
75
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 72

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#certsZlistx

Return a list of all the certificates in the store. The caller takes ownership of the zlistx_t object and is responsible for destroying it. The caller does not take ownership of the zcert_t objects.

Returns:

Raises:



201
202
203
204
205
206
207
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 201

def certs()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_certs(self_p)
  result = Zlistx.__new result, true
  result
end

#destroyvoid

This method returns an undefined value.

Destroy a certificate store object in memory. Does not affect anything stored on disk.



127
128
129
130
131
132
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 127

def destroy()
  return unless @ptr
  self_p = __ptr_give_ref
  result = ::CZMQ::FFI.zcertstore_destroy(self_p)
  result
end

#emptyvoid

This method returns an undefined value.

Empty certificate hashtable. This wrapper exists to be friendly to bindings, which don’t usually have access to struct internals.

Raises:



178
179
180
181
182
183
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 178

def empty()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_empty(self_p)
  result
end

#insert(cert_p) ⇒ void

This method returns an undefined value.

Insert certificate into certificate store in memory. Note that this does not save the certificate to disk. To do that, use zcert_save() directly on the certificate. Takes ownership of zcert_t object.

Parameters:

Raises:



166
167
168
169
170
171
172
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 166

def insert(cert_p)
  raise DestroyedError unless @ptr
  self_p = @ptr
  cert_p = cert_p.__ptr_give_ref
  result = ::CZMQ::FFI.zcertstore_insert(self_p, cert_p)
  result
end

#lookup(public_key) ⇒ Zcert

Look up certificate by public key, returns zcert_t object if found, else returns NULL. The public key is provided in Z85 text format.

Parameters:

  • public_key (String, #to_s, nil)

Returns:

Raises:



152
153
154
155
156
157
158
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 152

def lookup(public_key)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_lookup(self_p, public_key)
  result = Zcert.__new result, false
  result
end

#null?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 44

def null?
  !@ptr or @ptr.null?
end

This method returns an undefined value.

Print list of certificates in store to logging facility

Raises:



188
189
190
191
192
193
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 188

def print()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_print(self_p)
  result
end

#set_loader(loader, destructor, state) ⇒ void

This method returns an undefined value.

Override the default disk loader with a custom loader fn.

Parameters:

  • loader (::FFI::Pointer, #to_ptr)
  • destructor (::FFI::Pointer, #to_ptr)
  • state (::FFI::Pointer, #to_ptr)

Raises:



140
141
142
143
144
145
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 140

def set_loader(loader, destructor, state)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_set_loader(self_p, loader, destructor, state)
  result
end

#state::FFI::Pointer

Return the state stored in certstore

Returns:

  • (::FFI::Pointer)

Raises:



212
213
214
215
216
217
# File 'lib/czmq-ffi-gen/czmq/ffi/zcertstore.rb', line 212

def state()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcertstore_state(self_p)
  result
end