Module: RbNaCl::Sodium
- Included in:
- AEAD::ChaCha20Poly1305IETF, AEAD::ChaCha20Poly1305Legacy, AEAD::XChaCha20Poly1305IETF, Boxes::Curve25519XSalsa20Poly1305, Boxes::Curve25519XSalsa20Poly1305::PrivateKey, Boxes::Sealed, GroupElements::Curve25519, HMAC::SHA256, HMAC::SHA512, HMAC::SHA512256, Hash::Blake2b, Hash::SHA256, Hash::SHA512, OneTimeAuths::Poly1305, PasswordHash::Argon2, PasswordHash::SCrypt, Random, RbNaCl::SecretBoxes::XSalsa20Poly1305, RbNaCl::Signatures::Ed25519, RbNaCl::Signatures::Ed25519::SigningKey, RbNaCl::Signatures::Ed25519::VerifyKey, Version, Util
- Defined in:
- lib/rbnacl/sodium.rb,
lib/rbnacl/sodium/version.rb
Overview
Provides helpers for defining the libsodium bindings
Defined Under Namespace
Modules: Version
Instance Method Summary collapse
- #primitive ⇒ Object
- #sodium_constant(constant, name: constant, fallback: nil) ⇒ Object
- #sodium_function(name, function, arguments) ⇒ Object
- #sodium_function_with_return_code(name, function, arguments) ⇒ Object
- #sodium_primitive(primitive = nil) ⇒ Object
- #sodium_type(type = nil) ⇒ Object
Instance Method Details
#primitive ⇒ Object
28 29 30 |
# File 'lib/rbnacl/sodium.rb', line 28 def primitive sodium_primitive end |
#sodium_constant(constant, name: constant, fallback: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rbnacl/sodium.rb', line 32 def sodium_constant(constant, name: constant, fallback: nil) fn_name_components = ["crypto", sodium_type, sodium_primitive, constant.to_s.downcase] fn_name = fn_name_components.compact.join("_") begin attach_function fn_name, [], :size_t rescue FFI::NotFoundError raise if fallback.nil? define_singleton_method fn_name, -> { fallback } end const_set(name, public_send(fn_name)) end |
#sodium_function(name, function, arguments) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/rbnacl/sodium.rb', line 47 def sodium_function(name, function, arguments) module_eval <<-RUBY, __FILE__, __LINE__ + 1 attach_function #{function.inspect}, #{arguments.inspect}, :int def self.#{name}(*args) ret = #{function}(*args) ret == 0 end RUBY end |
#sodium_function_with_return_code(name, function, arguments) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rbnacl/sodium.rb', line 57 def sodium_function_with_return_code(name, function, arguments) module_eval <<-RUBY, __FILE__, __LINE__ + 1 attach_function #{function.inspect}, #{arguments.inspect}, :int def self.#{name}(*args) #{function}(*args) end RUBY end |
#sodium_primitive(primitive = nil) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rbnacl/sodium.rb', line 20 def sodium_primitive(primitive = nil) if primitive.nil? @primitive if defined?(@primitive) else @primitive = primitive end end |
#sodium_type(type = nil) ⇒ Object
14 15 16 17 18 |
# File 'lib/rbnacl/sodium.rb', line 14 def sodium_type(type = nil) return @type if type.nil? @type = type end |