Class: CryptoToolchain::DiffieHellman::Messages::KeyExchange

Inherits:
Object
  • Object
show all
Defined in:
lib/crypto_toolchain/diffie_hellman/messages.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(peer:, pubkey:, p: nil, g: nil, initial: false) ⇒ KeyExchange

Returns a new instance of KeyExchange.



18
19
20
21
22
23
24
25
26
27
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 18

def initialize(peer: , pubkey: , p: nil, g: nil, initial: false)
  if initial && (p.nil? || g.nil?)
    raise ArgumentError.new("Initial message must provide p and g")
  end
  @p = p
  @g = g
  @pubkey = pubkey
  @peer = peer
  @initial = initial
end

Instance Attribute Details

#gObject (readonly)

Returns the value of attribute g.



28
29
30
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 28

def g
  @g
end

#initialObject (readonly) Also known as: initial?

Returns the value of attribute initial.



28
29
30
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 28

def initial
  @initial
end

#pObject (readonly)

Returns the value of attribute p.



28
29
30
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 28

def p
  @p
end

#peerObject (readonly)

Returns the value of attribute peer.



28
29
30
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 28

def peer
  @peer
end

#pubkeyObject (readonly)

Returns the value of attribute pubkey.



28
29
30
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 28

def pubkey
  @pubkey
end

Instance Method Details

#to_sObject



31
32
33
# File 'lib/crypto_toolchain/diffie_hellman/messages.rb', line 31

def to_s
  "PEER: #{peer.name} P: #{p} G: #{g} PUBKEY: #{pubkey % 1000}"
end