Module: Solace::Utils::Curve25519Dalek

Extended by:
FFI::Library
Defined in:
lib/solace/utils/curve25519_dalek.rb

Constant Summary collapse

LIB_PATH =

The path to the native library

Returns:

  • (String)

    The path to the native library

File.expand_path(libfile, __dir__)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.on_curve?(bytes) ⇒ Boolean

Checks if a point is on the curve

Parameters:

  • bytes (Array)

    The bytes to check

Returns:

  • (Boolean)

    True if the point is on the curve, false otherwise

Raises:

  • (ArgumentError)

    If the input is not 32 bytes



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/solace/utils/curve25519_dalek.rb', line 43

def self.on_curve?(bytes)
  raise ArgumentError, 'Must be 32 bytes' unless bytes.bytesize == 32

  FFI::MemoryPointer.new(:uchar, 32) do |ptr|
    ptr.put_bytes(0, bytes)
    result = Curve25519Dalek.is_on_curve(ptr)

    case result
    when 1 then return true
    when 0 then return false
    else raise "Unexpected return code from native is_on_curve: #{result}"
    end
  end
end

Instance Method Details

#is_on_curveFFI::Function

Attach the native function

Returns:

  • (FFI::Function)

    The native function



36
# File 'lib/solace/utils/curve25519_dalek.rb', line 36

attach_function :is_on_curve, [:pointer], :int