Class: CryptoToolchain::DiffieHellman::PeerInfo
- Defined in:
- lib/crypto_toolchain/diffie_hellman/peer_info.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#g ⇒ Object
Returns the value of attribute g.
-
#p ⇒ Object
Returns the value of attribute p.
-
#peer ⇒ Object
readonly
Returns the value of attribute peer.
-
#pubkey ⇒ Object
Returns the value of attribute pubkey.
-
#shared_secret ⇒ Object
readonly
Returns the value of attribute shared_secret.
Instance Method Summary collapse
-
#initialize(peer:, channel:, pubkey: nil, p: nil, g: nil) ⇒ PeerInfo
constructor
A new instance of PeerInfo.
- #session_key ⇒ Object
- #set_shared_secret(privkey, override: nil) ⇒ Object
- #to_h ⇒ Object
- #update(hsh) ⇒ Object
Constructor Details
#initialize(peer:, channel:, pubkey: nil, p: nil, g: nil) ⇒ PeerInfo
Returns a new instance of PeerInfo.
4 5 6 7 8 9 10 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 4 def initialize(peer: , channel: , pubkey: nil, p: nil, g: nil) @peer = peer @channel = channel @pubkey = pubkey @p = p @g = g end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
11 12 13 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 11 def channel @channel end |
#g ⇒ Object
Returns the value of attribute g.
12 13 14 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 12 def g @g end |
#p ⇒ Object
Returns the value of attribute p.
12 13 14 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 12 def p @p end |
#peer ⇒ Object (readonly)
Returns the value of attribute peer.
11 12 13 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 11 def peer @peer end |
#pubkey ⇒ Object
Returns the value of attribute pubkey.
12 13 14 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 12 def pubkey @pubkey end |
#shared_secret ⇒ Object (readonly)
Returns the value of attribute shared_secret.
11 12 13 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 11 def shared_secret @shared_secret end |
Instance Method Details
#session_key ⇒ Object
28 29 30 31 32 33 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 28 def session_key if shared_secret.nil? raise ArgumentError.new("Session key requires a shared secret") end @session_key ||= CryptoToolchain::Utilities::SHA1.bindigest(shared_secret.to_s)[0..15] end |
#set_shared_secret(privkey, override: nil) ⇒ Object
24 25 26 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 24 def set_shared_secret(privkey, override: nil) @shared_secret = override ? override : pubkey.modexp(privkey, p) end |
#to_h ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 14 def to_h { name: peer.name, p: p, g: g, pubkey: pubkey, secret: shared_secret } end |
#update(hsh) ⇒ Object
35 36 37 38 39 |
# File 'lib/crypto_toolchain/diffie_hellman/peer_info.rb', line 35 def update(hsh) hsh.each do |k, v| self.send("#{k}=", v) unless v.nil? end end |