Module: Vines::Kit
- Defined in:
- lib/vines/kit.rb
Overview
A module for utility methods with no better home.
Class Method Summary collapse
-
.hmac(key, data) ⇒ Object
Create a hex-encoded, SHA-512 HMAC of the data, using the secret key.
-
.uuid ⇒ Object
Generates a random uuid per rfc 4122 that’s useful for including in stream, iq, and other xmpp stanzas.
Class Method Details
.hmac(key, data) ⇒ Object
Create a hex-encoded, SHA-512 HMAC of the data, using the secret key.
9 10 11 12 |
# File 'lib/vines/kit.rb', line 9 def self.hmac(key, data) digest = OpenSSL::Digest::Digest.new("sha512") OpenSSL::HMAC.hexdigest(digest, key, data) end |
.uuid ⇒ Object
Generates a random uuid per rfc 4122 that’s useful for including in stream, iq, and other xmpp stanzas.
16 17 18 19 20 21 |
# File 'lib/vines/kit.rb', line 16 def self.uuid hex = (0...16).map { "%02x" % rand(256) }.join hex[12] = '4' hex[16] = %w[8 9 a b][rand(4)] hex.scan(/(\w{8})(\w{4})(\w{4})(\w{4})(\w{12})/).first.join('-') end |