Class: CZMQ::FFI::Zcert

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

Overview

Note:

This class is 100% generated using zproject.

work with CURVE security certificates

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zcert

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/zcert.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/zcert.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/zcert.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.zcert_destroy ptr_ptr
  end
end

.load(filename) ⇒ CZMQ::Zcert

Load certificate from file

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (CZMQ::Zcert)


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

def self.load(filename)
  ptr = ::CZMQ::FFI.zcert_load(filename)
  __new ptr
end

.newCZMQ::Zcert

Create and initialize a new certificate in memory

Returns:

  • (CZMQ::Zcert)


79
80
81
82
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 79

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

.new_from(public_key, secret_key) ⇒ CZMQ::Zcert

Accepts public/secret key pair from caller

Parameters:

  • public_key (::FFI::Pointer, #to_ptr)
  • secret_key (::FFI::Pointer, #to_ptr)

Returns:

  • (CZMQ::Zcert)


88
89
90
91
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 88

def self.new_from(public_key, secret_key)
  ptr = ::CZMQ::FFI.zcert_new_from(public_key, secret_key)
  __new ptr
end

.new_from_txt(public_txt, secret_txt) ⇒ CZMQ::Zcert

Accepts public/secret key text pair from caller

Parameters:

  • public_txt (String, #to_s, nil)
  • secret_txt (String, #to_s, nil)

Returns:

  • (CZMQ::Zcert)


97
98
99
100
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 97

def self.new_from_txt(public_txt, secret_txt)
  ptr = ::CZMQ::FFI.zcert_new_from_txt(public_txt, secret_txt)
  __new ptr
end

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class

Parameters:

  • verbose (Boolean)


293
294
295
296
297
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 293

def self.test(verbose)
  verbose = !(0==verbose||!verbose) # boolean
  result = ::CZMQ::FFI.zcert_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/zcert.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/zcert.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/zcert.rb', line 72

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#apply(socket) ⇒ void

This method returns an undefined value.

Apply certificate to socket, i.e. use for CURVE security on socket. If certificate was loaded from public file, the secret key will be undefined, and this certificate will not work successfully.

Parameters:

  • socket (::FFI::Pointer, #to_ptr)

Raises:



248
249
250
251
252
253
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 248

def apply(socket)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_apply(self_p, socket)
  result
end

#destroyvoid

This method returns an undefined value.

Destroy a certificate in memory



113
114
115
116
117
118
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 113

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

#dupZcert

Return copy of certificate; if certificate is NULL or we exhausted heap memory, returns NULL.

Returns:

Raises:



259
260
261
262
263
264
265
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 259

def dup()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_dup(self_p)
  result = Zcert.__new result, true
  result
end

#eq(compare) ⇒ Boolean

Return true if two certificates have the same keys

Parameters:

Returns:

  • (Boolean)

Raises:



271
272
273
274
275
276
277
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 271

def eq(compare)
  raise DestroyedError unless @ptr
  self_p = @ptr
  compare = compare.__ptr if compare
  result = ::CZMQ::FFI.zcert_eq(self_p, compare)
  result
end

#meta(name) ⇒ String

Get metadata value from certificate; if the metadata value doesn’t exist, returns NULL.

Parameters:

  • name (String, #to_s, nil)

Returns:

  • (String)

Raises:



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

def meta(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_meta(self_p, name)
  result
end

#meta_keysZlist

Get list of metadata fields from certificate. Caller is responsible for destroying list. Caller should not modify the values of list items.

Returns:

Raises:



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

def meta_keys()
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_meta_keys(self_p)
  result = Zlist.__new result, false
  result
end

#null?Boolean

Returns:

  • (Boolean)


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

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

This method returns an undefined value.

Print certificate contents to stdout

Raises:



282
283
284
285
286
287
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 282

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

#public_key::FFI::Pointer

Return public part of key pair as 32-byte binary string

Returns:

  • (::FFI::Pointer)

Raises:



123
124
125
126
127
128
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 123

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

#public_txtString

Return public part of key pair as Z85 armored string

Returns:

  • (String)

Raises:



143
144
145
146
147
148
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 143

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

#save(filename) ⇒ Integer

Save full certificate (public + secret) to file for persistent storage This creates one public file and one secret file (filename + “_secret”).

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



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

def save(filename)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_save(self_p, filename)
  result
end

#save_public(filename) ⇒ Integer

Save public certificate only to file for persistent storage

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



224
225
226
227
228
229
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 224

def save_public(filename)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_save_public(self_p, filename)
  result
end

#save_secret(filename) ⇒ Integer

Save secret certificate only to file for persistent storage

Parameters:

  • filename (String, #to_s, nil)

Returns:

  • (Integer)

Raises:



235
236
237
238
239
240
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 235

def save_secret(filename)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_save_secret(self_p, filename)
  result
end

#secret_key::FFI::Pointer

Return secret part of key pair as 32-byte binary string

Returns:

  • (::FFI::Pointer)

Raises:



133
134
135
136
137
138
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 133

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

#secret_txtString

Return secret part of key pair as Z85 armored string

Returns:

  • (String)

Raises:



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

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

#set_meta(name, format, *args) ⇒ void

This method returns an undefined value.

Set certificate metadata from formatted string.

Parameters:

Raises:



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

def set_meta(name, format, *args)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_set_meta(self_p, name, format, *args)
  result
end

#unset_meta(name) ⇒ void

This method returns an undefined value.

Unset certificate metadata.

Parameters:

  • name (String, #to_s, nil)

Raises:



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

def unset_meta(name)
  raise DestroyedError unless @ptr
  self_p = @ptr
  result = ::CZMQ::FFI.zcert_unset_meta(self_p, name)
  result
end