Class: Nuckle::PublicKey

Inherits:
Object
  • Object
show all
Defined in:
lib/nuckle/public_key.rb

Overview

An X25519 (Curve25519) public key.

Constant Summary collapse

BYTES =

Key length in bytes.

32

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ PublicKey

Returns a new instance of PublicKey.

Parameters:

  • key (String)

    32-byte raw public key (binary)

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
# File 'lib/nuckle/public_key.rb', line 11

def initialize(key)
  key = key.to_s if key.respond_to?(:to_s) && !key.is_a?(String)
  key = key.b
  raise ArgumentError, "public key must be #{BYTES} bytes (got #{key.bytesize})" unless key.bytesize == BYTES

  @key = key
end

Instance Method Details

#==(other) ⇒ Boolean

Constant-time equality comparison.

Parameters:

Returns:

  • (Boolean)


29
30
31
# File 'lib/nuckle/public_key.rb', line 29

def ==(other)
  other.is_a?(PublicKey) && Util.verify32(@key, other.to_s)
end

#to_bytesString

Returns raw 32-byte key (binary).

Returns:

  • (String)

    raw 32-byte key (binary)



21
22
# File 'lib/nuckle/public_key.rb', line 21

def to_bytes = @key
# @return [String] raw 32-byte key (binary)

#to_sString

Returns raw 32-byte key (binary).

Returns:

  • (String)

    raw 32-byte key (binary)



23
# File 'lib/nuckle/public_key.rb', line 23

def to_s     = @key