Module: Vines::Kit
- Defined in:
- lib/vines/kit.rb
Overview
A module for utility methods with no better home.
Class Method Summary collapse
-
.auth_token ⇒ Object
Generates a random 128 character authentication token.
-
.dialback_key(receiving_server, originating_server, stream_id) ⇒ Object
Generates dialback key as described in XEP-0185.
-
.hmac(key, data) ⇒ Object
Create a hex-encoded, SHA-512 HMAC of the data, using the secret key.
- .local_ip ⇒ Object
-
.uuid ⇒ Object
Generates a random uuid per rfc 4122 that’s useful for including in stream, iq, and other xmpp stanzas.
Class Method Details
.auth_token ⇒ Object
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(receiving_server, originating_server, stream_id) ⇒ Object
Generates dialback key as described in XEP-0185
36 37 38 39 40 |
# File 'lib/vines/kit.rb', line 36 def self.dialback_key(receiving_server, originating_server, stream_id) sha = Digest::SHA2.new(256) sha.update("#{receiving_server} #{originating_server} #{stream_id}") sha.to_s 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::Digest.new("sha512") OpenSSL::HMAC.hexdigest(digest, key, data) end |
.local_ip ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vines/kit.rb', line 23 def self.local_ip orig = Socket.do_not_reverse_lookup Socket.do_not_reverse_lookup = true UDPSocket.open do |s| s.connect '64.223.187.99', 1 s.addr.last end ensure Socket.do_not_reverse_lookup = orig end |
.uuid ⇒ Object
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 |