Module: RbNaCl::Sodium

Overview

Provides helpers for defining the libsodium bindings

Defined Under Namespace

Modules: Version

Instance Method Summary collapse

Instance Method Details

#primitiveObject



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

def primitive
  sodium_primitive
end

#sodium_constant(constant, name = constant) ⇒ Object



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

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

#sodium_function(name, function, arguments) ⇒ Object



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

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

#sodium_function_with_return_code(name, function, arguments) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/rbnacl/sodium.rb', line 48

def sodium_function_with_return_code(name, function, arguments)
  module_eval "  attach_function \#{function.inspect}, \#{arguments.inspect}, :int\n  def self.\#{name}(*args)\n    \#{function}(*args)\n  end\n  eos\nend\n", __FILE__, __LINE__ + 1

#sodium_primitive(primitive = nil) ⇒ Object



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

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

#sodium_type(type = nil) ⇒ Object



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

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