File: rsa_pss.rb

package info (click to toggle)
ruby-cose 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272 kB
  • sloc: ruby: 993; sh: 5; makefile: 4
file content (43 lines) | stat: -rw-r--r-- 908 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require "cose/algorithm/signature_algorithm"
require "cose/key/rsa"
require "cose/error"
require "openssl"
require "openssl/signature_algorithm/rsapss"

module COSE
  module Algorithm
    class RSAPSS < SignatureAlgorithm
      attr_reader :hash_function, :salt_length

      def initialize(*args, hash_function:, salt_length:)
        super(*args)

        @hash_function = hash_function
        @salt_length = salt_length
      end

      private

      def valid_key?(key)
        to_cose_key(key).is_a?(COSE::Key::RSA)
      end

      def signature_algorithm_class
        OpenSSL::SignatureAlgorithm::RSAPSS
      end

      def to_pkey(key)
        case key
        when COSE::Key::RSA
          key.to_pkey
        when OpenSSL::PKey::RSA
          key
        else
          raise(COSE::Error, "Incompatible key for algorithm")
        end
      end
    end
  end
end