Class: Confium::Digest

Inherits:
Digest::Class
  • Object
show all
Defined in:
lib/confium/digest.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfm, name) ⇒ Digest

Returns a new instance of Digest.



9
10
11
12
13
14
15
16
# File 'lib/confium/digest.rb', line 9

def initialize(cfm, name)
  @name = name
  pptr = FFI::MemoryPointer.new(:pointer)
  Confium.call_ffi(:cfm_hash_create, cfm.ptr, pptr, name, nil, nil, nil)
  ptr = pptr.read_pointer
  raise if ptr.null?
  @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy))
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/confium/digest.rb', line 6

def name
  @name
end

#ptrObject (readonly)

Returns the value of attribute ptr.



7
8
9
# File 'lib/confium/digest.rb', line 7

def ptr
  @ptr
end

Class Method Details

.destroy(ptr) ⇒ Object



26
27
28
# File 'lib/confium/digest.rb', line 26

def self.destroy(ptr)
  Confium::Lib.cfm_hash_destroy(ptr)
end

Instance Method Details

#block_lengthObject



30
31
32
33
34
# File 'lib/confium/digest.rb', line 30

def block_length
  plength = FFI::MemoryPointer.new(:uint32)
  Confium.call_ffi(:cfm_hash_block_size, @ptr, plength)
  plength.read(:uint32)
end

#digest_lengthObject



36
37
38
39
40
# File 'lib/confium/digest.rb', line 36

def digest_length
  plength = FFI::MemoryPointer.new(:uint32)
  Confium.call_ffi(:cfm_hash_output_size, @ptr, plength)
  plength.read(:uint32)
end

#finishObject



52
53
54
55
56
# File 'lib/confium/digest.rb', line 52

def finish
  buf = FFI::MemoryPointer.new(:uint8, digest_length)
  Confium.call_ffi(:cfm_hash_finalize, @ptr, buf, buf.size)
  buf.read_bytes(buf.size)
end

#initialize_copy(source) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/confium/digest.rb', line 18

def initialize_copy(source)
  @name = source.name
  pptr = FFI::MemoryPointer.new(:pointer)
  Confium.call_ffi(:cfm_hash_clone, source.ptr, pptr)
  ptr = pptr.read_pointer
  @ptr = FFI::AutoPointer.new(ptr, self.class.method(:destroy))
end

#resetObject



47
48
49
50
# File 'lib/confium/digest.rb', line 47

def reset
  Confium.call_ffi(:cfm_hash_reset, @ptr)
  self
end

#update(data) ⇒ Object Also known as: <<



42
43
44
45
# File 'lib/confium/digest.rb', line 42

def update(data)
  Confium.call_ffi(:cfm_hash_update, @ptr, data, data.bytesize)
  self
end