Sha256: e572b8763723a81c3d6a1da610e1087f6bc8eb4d911851214dc917c04af0bc5b

Contents?: true

Size: 547 Bytes

Versions: 8

Compression:

Stored size: 547 Bytes

Contents

# -*- coding: binary -*-

module Rex
module Proto
module Kademlia
  # Decodes an on-the-wire representation of a Kademlia peer to its 16-character hex equivalent
  #
  # @param bytes [String] the on-the-wire representation of a Kademlia peer
  # @return [String] the peer ID if valid, nil otherwise
  def self.decode_peer_id(bytes)
    peer_id = 0
    return nil unless bytes.size == 16
    bytes.unpack('VVVV').map { |p| peer_id = ((peer_id << 32) ^ p) }
    peer_id.to_s(16).upcase
  end

  # TODO
  # def encode_peer_id(id)
  # end
end
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rex-2.0.13 lib/rex/proto/kademlia/util.rb
rex-2.0.12 lib/rex/proto/kademlia/util.rb
rex-2.0.11 lib/rex/proto/kademlia/util.rb
rex-2.0.10 lib/rex/proto/kademlia/util.rb
rex-2.0.9 lib/rex/proto/kademlia/util.rb
rex-2.0.8 lib/rex/proto/kademlia/util.rb
rex-2.0.7 lib/rex/proto/kademlia/util.rb
rex-2.0.5 lib/rex/proto/kademlia/util.rb