Module: RbNaCl::Sodium

Overview

Provides helpers for defining the libsodium bindings

Defined Under Namespace

Modules: Version

Instance Method Summary collapse

Instance Method Details

#primitiveObject



27
28
29
# File 'lib/rbnacl/sodium.rb', line 27

def primitive
  sodium_primitive
end

#sodium_constant(constant, name = constant) ⇒ Object



31
32
33
34
35
# File 'lib/rbnacl/sodium.rb', line 31

def sodium_constant(constant, name=constant)
  fn = "crypto_#{sodium_type}_#{sodium_primitive}_#{constant.to_s.downcase}"
  attach_function fn, [], :ulong_long
  self.const_set(name, self.public_send(fn))
end

#sodium_function(name, function, arguments) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rbnacl/sodium.rb', line 37

def sodium_function(name, function, arguments)
  self.module_eval <<-eos, __FILE__, __LINE__ + 1
  attach_function #{function.inspect}, #{arguments.inspect}, :int
  def self.#{name}(*args)
    ret = #{function}(*args)
    ret == 0
  end
  eos
end

#sodium_primitive(primitive = nil) ⇒ Object



22
23
24
25
# File 'lib/rbnacl/sodium.rb', line 22

def sodium_primitive(primitive = nil)
  return @primitive if primitive.nil?
  @primitive = primitive
end

#sodium_type(type = nil) ⇒ Object



17
18
19
20
# File 'lib/rbnacl/sodium.rb', line 17

def sodium_type(type = nil)
  return @type if type.nil?
  @type = type
end