Class: Onionurigen::AddressFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/onionurigen/address_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(match, multi_threading = false) ⇒ AddressFinder

Returns a new instance of AddressFinder.



16
17
18
19
20
21
# File 'lib/onionurigen/address_finder.rb', line 16

def initialize(match, multi_threading = false)
  raise 'Invalid Pattern' unless [String, Regexp].include?(match.class)
  @found = false
  @match = match.class.eql?(String) ? /\A#{Regexp.quote(match.upcase)}/ : match
  multi_threading ? multi_thread_process : single_thread_process
end

Instance Attribute Details

#foundObject (readonly)

Returns the value of attribute found.



14
15
16
# File 'lib/onionurigen/address_finder.rb', line 14

def found
  @found
end

#matchObject (readonly)

Returns the value of attribute match.



14
15
16
# File 'lib/onionurigen/address_finder.rb', line 14

def match
  @match
end

#onion_urlObject (readonly)

Returns the value of attribute onion_url.



14
15
16
# File 'lib/onionurigen/address_finder.rb', line 14

def onion_url
  @onion_url
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



14
15
16
# File 'lib/onionurigen/address_finder.rb', line 14

def private_key
  @private_key
end

#rsaObject (readonly)

Returns the value of attribute rsa.



14
15
16
# File 'lib/onionurigen/address_finder.rb', line 14

def rsa
  @rsa
end

Instance Method Details

#found?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/onionurigen/address_finder.rb', line 43

def found?
  @found
end

#multi_thread_processObject



33
34
35
36
37
38
39
40
41
# File 'lib/onionurigen/address_finder.rb', line 33

def multi_thread_process
  @rsa = Onionurigen::RSAGen.new
  @spki = Onionurigen::SPKI.new(@rsa)
  if @spki.encoded =~ @match
    @found = true
    @private_key = @rsa.private_key.to_pem_pkcs8
    @onion_url = "http://#{@spki.encoded.downcase}.onion"
  end
end

#single_thread_processObject



23
24
25
26
27
28
29
30
31
# File 'lib/onionurigen/address_finder.rb', line 23

def single_thread_process
  loop do
    @rsa = Onionurigen::RSAGen.new
    @spki = Onionurigen::SPKI.new(@rsa)
    break if @spki.encoded =~ @match
  end
  @private_key = @rsa.private_key.to_pem_pkcs8
  @onion_url = "http://#{@spki.encoded.downcase}.onion"
end