Class: Onionurigen::SPKI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rsa) ⇒ SPKI

Returns a new instance of SPKI.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/onionurigen/spki.rb', line 8

def initialize(rsa)
  raise 'Object must be of RSAGen Type' unless rsa.class.eql?(Onionurigen::RSAGen)
  @rsa = rsa
  # Export the DER encoding of the SubjectPublicKeyInfo structure.
  @der = @rsa.public_key.to_der
  # Compute the SHA-1 digest of the SPKI.
  # Skip 22 bytes (the SPKI header) that are ignored by Tor.
  @digest = OpenSSL::Digest::SHA1.digest @der[22..-1]
  # Base32-encode the first half of the digest.
  @encoded = Base32.encode(@digest[0..9])
end

Instance Attribute Details

#derObject

Returns the value of attribute der.



6
7
8
# File 'lib/onionurigen/spki.rb', line 6

def der
  @der
end

#digestObject

Returns the value of attribute digest.



6
7
8
# File 'lib/onionurigen/spki.rb', line 6

def digest
  @digest
end

#encodedObject

Returns the value of attribute encoded.



6
7
8
# File 'lib/onionurigen/spki.rb', line 6

def encoded
  @encoded
end

#rsaObject

Returns the value of attribute rsa.



6
7
8
# File 'lib/onionurigen/spki.rb', line 6

def rsa
  @rsa
end