File: sign_key_fixture_helper.rb

package info (click to toggle)
ruby-json-jwt 1.6.2-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 292 kB
  • sloc: ruby: 2,120; makefile: 3
file content (52 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
module SignKeyFixtureHelper
  def shared_secret
    'shared-secret'
  end

  def pem_file(file_name)
    File.new pem_file_path(file_name)
  end

  def pem_file_path(file_name)
    File.join(
      File.dirname(__FILE__),
      "../fixtures/#{file_name}.pem"
    )
  end

  def der_file_path(file_name)
    File.join(
      File.dirname(__FILE__),
      "../fixtures/#{file_name}.der"
    )
  end

  def private_key(algorithm = :rsa, options = {})
    case algorithm
    when :rsa
      OpenSSL::PKey::RSA.new(
        pem_file("#{algorithm}/private_key"),
        'pass-phrase'
      )
    when :ecdsa
      OpenSSL::PKey::EC.new(
        pem_file("#{algorithm}/#{options[:digest_length] || 256}/private_key")
      )
    end
  end

  def public_key(algorithm = :rsa, options = {})
    case algorithm
    when :rsa
      OpenSSL::PKey::RSA.new(
        pem_file("#{algorithm}/public_key")
      )
    when :ecdsa
      OpenSSL::PKey::EC.new(
        pem_file("#{algorithm}/#{options[:digest_length] || 256}/public_key")
      )
    end
  end
end

include SignKeyFixtureHelper