Class: CZMQ::FFI::Zdigest
- Inherits:
-
Object
- Object
- CZMQ::FFI::Zdigest
- Defined in:
- lib/czmq-ffi-gen/czmq/ffi/zdigest.rb
Overview
This class is 100% generated using zproject.
provides hashing functions (SHA-1 at present)
Defined Under Namespace
Classes: DestroyedError
Class Method Summary collapse
- .__new ⇒ Object
- .create_finalizer_for(ptr) ⇒ Proc
-
.new ⇒ CZMQ::Zdigest
Constructor - creates new digest object, which you use to build up a digest by repeatedly calling zdigest_update() on chunks of data.
-
.test(verbose) ⇒ void
Self test of this class.
Instance Method Summary collapse
-
#__ptr ⇒ ::FFI::Pointer
(also: #to_ptr)
Return internal pointer.
-
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
Nullify internal pointer and return pointer pointer.
-
#__undef_finalizer ⇒ void
Undefines the finalizer for this object.
-
#data ⇒ ::FFI::Pointer
Return final digest hash data.
-
#destroy ⇒ void
Destroy a digest object.
-
#initialize(ptr, finalize = true) ⇒ Zdigest
constructor
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
- #null? ⇒ Boolean
-
#size ⇒ Integer
Return final digest hash size.
-
#string ⇒ ::FFI::Pointer
Return digest as printable hex string; caller should not modify nor free this string.
-
#update(buffer, length) ⇒ void
Add buffer into digest calculation.
Constructor Details
#initialize(ptr, finalize = true) ⇒ Zdigest
Attaches the pointer ptr to this instance and defines a finalizer for it if necessary.
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
.__new ⇒ Object
18 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 18 alias :__new :new |
.create_finalizer_for(ptr) ⇒ Proc
35 36 37 38 39 40 41 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.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.zdigest_destroy ptr_ptr end end |
Instance Method Details
#__ptr ⇒ ::FFI::Pointer Also known as: to_ptr
Return internal pointer
48 49 50 51 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 48 def __ptr raise DestroyedError unless @ptr @ptr end |
#__ptr_give_ref ⇒ ::FFI::MemoryPointer
This detaches the current instance from the native object and thus makes it unusable.
Nullify internal pointer and return pointer pointer.
59 60 61 62 63 64 65 66 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.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_finalizer ⇒ void
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/zdigest.rb', line 71 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.
111 112 113 114 115 116 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 111 def data() raise DestroyedError unless @ptr self_p = @ptr result = ::CZMQ::FFI.zdigest_data(self_p) result end |
#destroy ⇒ void
This method returns an undefined value.
Destroy a digest object
87 88 89 90 91 92 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 87 def destroy() return unless @ptr self_p = __ptr_give_ref result = ::CZMQ::FFI.zdigest_destroy(self_p) result end |
#null? ⇒ Boolean
43 44 45 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 43 def null? !@ptr or @ptr.null? end |
#size ⇒ Integer
Return final digest hash size
121 122 123 124 125 126 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 121 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.
133 134 135 136 137 138 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 133 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
99 100 101 102 103 104 105 |
# File 'lib/czmq-ffi-gen/czmq/ffi/zdigest.rb', line 99 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 |