Module: Vines::Kit

Defined in:
lib/vines/kit.rb

Overview

A module for utility methods with no better home.

Class Method Summary collapse

Class Method Details

.auth_tokenObject

Generates a random 128 character authentication token.



19
20
21
# File 'lib/vines/kit.rb', line 19

def self.auth_token
  SecureRandom.hex(64)
end

.dialback_key(key, receiving, originating, id) ⇒ Object

Generate a HMAC for dialback as recommended in XEP-0185



24
25
26
27
28
# File 'lib/vines/kit.rb', line 24

def self.dialback_key(key, receiving, originating, id)
  digest = OpenSSL::Digest.new('sha256')
  data = "#{receiving} #{originating} #{id}"
  OpenSSL::HMAC.hexdigest(digest, digest.hexdigest(key), data)
end

.hmac(key, data) ⇒ Object

Create a hex-encoded, SHA-512 HMAC of the data, using the secret key.



7
8
9
10
# File 'lib/vines/kit.rb', line 7

def self.hmac(key, data)
  digest = OpenSSL::Digest.new("sha512")
  OpenSSL::HMAC.hexdigest(digest, key, data)
end

.uuidObject

Generates a random uuid per rfc 4122 that’s useful for including in stream, iq, and other xmpp stanzas.



14
15
16
# File 'lib/vines/kit.rb', line 14

def self.uuid
  SecureRandom.uuid
end