Class: Sigma::BoxId

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/sigma/ergo_box.rb

Overview

BoxId (32-byte digest)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointerObject

Returns the value of attribute pointer.



18
19
20
# File 'lib/sigma/ergo_box.rb', line 18

def pointer
  @pointer
end

Class Method Details

.with_raw_pointer(bid_ptr) ⇒ BoxId

Note:

A user of sigma_rb generally does not need to call this function

Takes ownership of an existing BoxId Pointer.

Parameters:

  • pointer (FFI::MemoryPointer)

Returns:



24
25
26
# File 'lib/sigma/ergo_box.rb', line 24

def self.with_raw_pointer(bid_ptr)
  init(bid_ptr)
end

.with_string(str) ⇒ BoxId

Parse box id (32 byte digest) from base16-encoded string

Parameters:

  • str (String)

Returns:



31
32
33
34
35
36
37
# File 'lib/sigma/ergo_box.rb', line 31

def self.with_string(str)
  bid_ptr = FFI::MemoryPointer.new(:pointer)
  error = ergo_lib_box_id_from_str(str, bid_ptr)
  Util.check_error!(error)

  init(bid_ptr)
end

Instance Method Details

#==(box_id_two) ⇒ bool

Equality check of two BoxId

Parameters:

Returns:

  • (bool)


61
62
63
# File 'lib/sigma/ergo_box.rb', line 61

def ==(box_id_two)
  ergo_lib_box_id_eq(self.pointer, box_id_two.pointer)
end

#to_bytesArray<uint8, 32>

Returns byte array (32-bytes) representation

Returns:

  • (Array<uint8, 32>)


41
42
43
44
45
# File 'lib/sigma/ergo_box.rb', line 41

def to_bytes
  b_ptr = FFI::MemoryPointer.new(:uint8, 32)
  ergo_lib_box_id_to_bytes(self.pointer, b_ptr)
  b_ptr.get_array_of_uint8(0, 32)
end

#to_sString

Returns base16 encoded string representation

Returns:

  • (String)


49
50
51
52
53
54
55
56
# File 'lib/sigma/ergo_box.rb', line 49

def to_s
  s_ptr = FFI::MemoryPointer.new(:pointer, 1)
  ergo_lib_box_id_to_str(self.pointer, s_ptr)
  s_ptr = s_ptr.read_pointer()
  str = s_ptr.read_string().force_encoding('UTF-8')
  Util.ergo_lib_delete_string(s_ptr)
  str
end