Class: CZMQ::FFI::Zdigest

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

Overview

Note:

This class is 100% generated using zproject.

provides hashing functions (SHA-1 at present)

Defined Under Namespace

Classes: DestroyedError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ptr, finalize = true) ⇒ Zdigest

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/zdigest.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/zdigest.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/zdigest.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.zdigest_destroy ptr_ptr
  end
end

.newCZMQ::Zdigest

Constructor - creates new digest object, which you use to build up a digest by repeatedly calling zdigest_update() on chunks of data.

Returns:

  • (CZMQ::Zdigest)


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

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

.test(verbose) ⇒ void

This method returns an undefined value.

Self test of this class.

Parameters:

  • verbose (Boolean)


145
146
147
148
149
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 145

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

def __undef_finalizer
  ObjectSpace.undefine_finalizer self
  @finalizer = nil
end

#data::FFI::Pointer

Return final digest hash data. If built without crypto support, returns NULL.

Returns:

  • (::FFI::Pointer)

Raises:



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

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

#destroyvoid

This method returns an undefined value.

Destroy a digest object



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

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

#null?Boolean

Returns:

  • (Boolean)


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

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

#sizeInteger

Return final digest hash size

Returns:

  • (Integer)

Raises:



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

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

#string::FFI::Pointer

Return digest as printable hex string; caller should not modify nor free this string. After calling this, you may not use zdigest_update() on the same digest. If built without crypto support, returns NULL.

Returns:

  • (::FFI::Pointer)

Raises:



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

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

#update(buffer, length) ⇒ void

This method returns an undefined value.

Add buffer into digest calculation

Parameters:

  • buffer (::FFI::Pointer, #to_ptr)
  • length (Integer, #to_int, #to_i)

Raises:



100
101
102
103
104
105
106
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 100

def update(buffer, length)
  raise DestroyedError unless @ptr
  self_p = @ptr
  length = Integer(length)
  result = ::CZMQ::FFI.zdigest_update(self_p, buffer, length)
  result
end