Sha256: 292e89992a5646949c892715ac1a69ced9111e92d1c0ad98cdd37604d4fc9138

Contents?: true

Size: 834 Bytes

Versions: 8

Compression:

Stored size: 834 Bytes

Contents

# encoding: UTF-8

module Vines
  # A module for utility methods with no better home.
  module Kit
    # Create a hex-encoded, SHA-512 HMAC of the data, using the secret key.
    def self.hmac(key, data)
      digest = OpenSSL::Digest::Digest.new("sha512")
      OpenSSL::HMAC.hexdigest(digest, key, data)
    end

    # Generates a random uuid per rfc 4122 that's useful for including in
    # stream, iq, and other xmpp stanzas.
    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

    # Generates a random 128 character authentication token.
    def self.auth_token
      hash = Digest::SHA512.new
      1024.times { hash << rand.to_s }
      hash.hexdigest
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vines-0.4.5 lib/vines/kit.rb
vines-0.4.4 lib/vines/kit.rb
vines-0.4.3 lib/vines/kit.rb
vines-0.4.2 lib/vines/kit.rb
vines-0.4.1 lib/vines/kit.rb
vines-0.4.0 lib/vines/kit.rb
vines-0.3.2 lib/vines/kit.rb
vines-0.3.1 lib/vines/kit.rb