File: rsapss.rb

package info (click to toggle)
ruby-openssl-signature-algorithm 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 200 kB
  • sloc: ruby: 268; sh: 4; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require "openssl"
require "openssl/signature_algorithm/rsa"

module OpenSSL
  module SignatureAlgorithm
    class RSAPSS < RSA
      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::SignatureVerificationError, "Signature verification failed")
      end

      def mgf1_hash_function
        hash_function
      end
    end
  end
end