Sha256: 151272c10413e26bd62225812f8894d5c55b9b5561a0c34e970455cd1c32e657

Contents?: true

Size: 595 Bytes

Versions: 1

Compression:

Stored size: 595 Bytes

Contents

require 'openssl'

module CiderCi
  module OpenSession
    module Signature
      class ValidationError < StandardError
      end

      extend self

      def create(secret, message)
        OpenSSL::HMAC.digest(
          OpenSSL::Digest.new('sha256'),
          secret, message)
      end

      def valid?(signature, secret, message)
        signature == create(secret, message)
      end

      def validate!(signature, secret, message)
        unless valid?(signature, secret, message)
          fail ValidationError, 'Signature validation failed!'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cider_ci-open_session-2.0.1 lib/cider_ci/open_session/signature.rb