Class: MTProto::Crypto::RSAKey

Inherits:
Object
  • Object
show all
Defined in:
lib/mtproto/crypto/rsa_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pem_string) ⇒ RSAKey

Returns a new instance of RSAKey.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/mtproto/crypto/rsa_key.rb', line 11

def initialize(pem_string)
  raise ArgumentError, "pem_string is required" if pem_string.nil? || pem_string.empty?

  @key = OpenSSL::PKey::RSA.new(pem_string)
  @fingerprint = calculate_fingerprint
end

Instance Attribute Details

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



9
10
11
# File 'lib/mtproto/crypto/rsa_key.rb', line 9

def fingerprint
  @fingerprint
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/mtproto/crypto/rsa_key.rb', line 9

def key
  @key
end

Class Method Details

.find_by_fingerprint(fingerprints, public_key) ⇒ Object

Raises:

  • (ArgumentError)


22
23
24
25
26
27
# File 'lib/mtproto/crypto/rsa_key.rb', line 22

def self.find_by_fingerprint(fingerprints, public_key)
  raise ArgumentError, "public_key is required" if public_key.nil? || public_key.empty?

  key = new(public_key)
  key if fingerprints.include?(key.fingerprint)
end

.from_pem(pem_string) ⇒ Object



18
19
20
# File 'lib/mtproto/crypto/rsa_key.rb', line 18

def self.from_pem(pem_string)
  new(pem_string)
end