aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart de Water <bartdewater@gmail.com>2019-10-20 16:17:07 -0400
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2019-11-01 10:52:25 +1300
commit5ae27f5872d8df4253a524b2e857409eb428adcc (patch)
tree8647780ca43f5b327c50f476735672d25af379c6
parentcac0272190353090c33a5f60d8103c2e1e846ada (diff)
downloadruby-openssl-5ae27f5872d8df4253a524b2e857409eb428adcc.tar.gz
Separate cert generation and issuance test helpers
-rw-r--r--test/utils.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/test/utils.rb b/test/utils.rb
index 126cb85d..36aeda05 100644
--- a/test/utils.rb
+++ b/test/utils.rb
@@ -60,11 +60,10 @@ module OpenSSL::TestUtils
module_function
- def issue_cert(dn, key, serial, extensions, issuer, issuer_key,
- not_before: nil, not_after: nil, digest: "sha256")
+ def generate_cert(dn, key, serial, issuer,
+ not_before: nil, not_after: nil)
cert = OpenSSL::X509::Certificate.new
issuer = cert unless issuer
- issuer_key = key unless issuer_key
cert.version = 2
cert.serial = serial
cert.subject = dn
@@ -73,6 +72,16 @@ module OpenSSL::TestUtils
now = Time.now
cert.not_before = not_before || now - 3600
cert.not_after = not_after || now + 3600
+ cert
+ end
+
+
+ def issue_cert(dn, key, serial, extensions, issuer, issuer_key,
+ not_before: nil, not_after: nil, digest: "sha256")
+ cert = generate_cert(dn, key, serial, issuer,
+ not_before: not_before, not_after: not_after)
+ issuer = cert unless issuer
+ issuer_key = key unless issuer_key
ef = OpenSSL::X509::ExtensionFactory.new
ef.subject_certificate = cert
ef.issuer_certificate = issuer