Sha256: 6f46c7e770df562797225d5e2e795159b1879fba1ffcd16f725281e45e6eae71

Contents?: true

Size: 650 Bytes

Versions: 4

Compression:

Stored size: 650 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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vines-0.2.1 lib/vines/kit.rb
vines-0.2.0 lib/vines/kit.rb
vines-0.1.1 lib/vines/kit.rb
vines-0.1.0 lib/vines/kit.rb