Sha256: 4c28637e16461c51a406ccef3929706255f272e3d9982e1fbf714c385b6fd93e

Contents?: true

Size: 945 Bytes

Versions: 3

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

require "openssl"
require "openssl/signature_algorithm/base"

module OpenSSL
  module SignatureAlgorithm
    class RSAPSS < Base
      class SigningKey < OpenSSL::PKey::RSA
        def verify_key
          public_key
        end
      end

      DEFAULT_KEY_SIZE = 2048

      def generate_signing_key(size: DEFAULT_KEY_SIZE)
        @signing_key = SigningKey.new(size)
      end

      def sign(data)
        signing_key.sign_pss(hash_function, data, salt_length: :max, mgf1_hash: mgf1_hash_function)
      end

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

      def mgf1_hash_function
        hash_function
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openssl-signature_algorithm-0.3.0 lib/openssl/signature_algorithm/rsapss.rb
openssl-signature_algorithm-0.2.0 lib/openssl/signature_algorithm/rsapss.rb
openssl-signature_algorithm-0.1.1 lib/openssl/signature_algorithm/rsapss.rb