File: crypto_spec_helper.rb

package info (click to toggle)
ruby-openid-connect 2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 528 kB
  • sloc: ruby: 3,002; makefile: 4
file content (31 lines) | stat: -rw-r--r-- 632 bytes parent folder | download | duplicates (4)
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
module CryptoSpecHelper
  def rsa_key
    @rsa_key ||= OpenSSL::PKey::RSA.generate 2048
  end

  def public_key
    @public_key ||= rsa_key.public_key
  end

  def private_key
    @private_key ||= OpenSSL::PKey::RSA.new rsa_key.export(OpenSSL::Cipher.new('DES-EDE3-CBC'), 'pass-phrase'), 'pass-phrase'
  end

  def ec_key
    @ec_key ||= OpenSSL::PKey::EC.new('prime256v1').generate_key
  end

  def ec_public_key
    unless @ec_public_key
      @ec_public_key = OpenSSL::PKey::EC.new ec_key
      @ec_public_key.private_key = nil
    end
    @ec_public_key
  end

  def ec_private_key
    ec_key
  end
end

include CryptoSpecHelper