Sha256: 805a1143b07be5971cd3e0e5a73bfeb6ac9738a2c90622c2ff3fc6d24e344f11

Contents?: true

Size: 716 Bytes

Versions: 2

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

require "openssl"
require "openssl/signature_algorithm/error"

module OpenSSL
  module SignatureAlgorithm
    class Base
      attr_reader :digest_length, :signing_key
      attr_accessor :verify_key

      def initialize(digest_length)
        @digest_length = digest_length
      end

      def sign(data)
        signing_key.sign(hash_function, data)
      end

      def hash_function
        OpenSSL::Digest.new("sha#{digest_length}")
      end

      def verify(signature, verification_data)
        verify_key.verify(hash_function, signature, verification_data) ||
          raise(OpenSSL::SignatureAlgorithm::Error, "Signature verification failed")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openssl-signature_algorithm-0.1.1 lib/openssl/signature_algorithm/base.rb
openssl-signature_algorithm-0.1.0 lib/openssl/signature_algorithm/base.rb