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
# File 'lib/czmq-ffi-gen/czmq/ffi/zcert.rb', line 35

def self.create_finalizer_for(ptr)
  Proc.new do
    ptr_ptr = ::FFI::MemoryPointer.new :pointer
    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)


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

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)


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

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)


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

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)


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

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)


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

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:



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

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:



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

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.



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

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:



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

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



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

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:



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

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:



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

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:



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

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:



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

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)


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

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

This method returns an undefined value.

Print certificate contents to stdout

Raises:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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:



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

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