@@ -11,7 +11,7 @@ def test_no_private_exp
11
11
key . set_factors ( rsa . p , rsa . q )
12
12
assert_raise ( OpenSSL ::PKey ::RSAError ) { key . private_encrypt ( "foo" ) }
13
13
assert_raise ( OpenSSL ::PKey ::RSAError ) { key . private_decrypt ( "foo" ) }
14
- end
14
+ end if ! openssl? ( 3 , 0 , 0 ) # Impossible state in OpenSSL 3.0
15
15
16
16
def test_private
17
17
# Generated by key size and public exponent
@@ -201,7 +201,7 @@ def test_sign_verify_pss
201
201
202
202
def test_encrypt_decrypt
203
203
rsapriv = Fixtures . pkey ( "rsa-1" )
204
- rsapub = dup_public ( rsapriv )
204
+ rsapub = OpenSSL :: PKey . read ( rsapriv . public_to_der )
205
205
206
206
# Defaults to PKCS #1 v1.5
207
207
raw = "data"
@@ -216,7 +216,7 @@ def test_encrypt_decrypt
216
216
217
217
def test_encrypt_decrypt_legacy
218
218
rsapriv = Fixtures . pkey ( "rsa-1" )
219
- rsapub = dup_public ( rsapriv )
219
+ rsapub = OpenSSL :: PKey . read ( rsapriv . public_to_der )
220
220
221
221
# Defaults to PKCS #1 v1.5
222
222
raw = "data"
@@ -346,13 +346,15 @@ def test_RSAPrivateKey_encrypted
346
346
347
347
def test_RSAPublicKey
348
348
rsa1024 = Fixtures . pkey ( "rsa1024" )
349
+ rsa1024pub = OpenSSL ::PKey ::RSA . new ( rsa1024 . public_to_der )
350
+
349
351
asn1 = OpenSSL ::ASN1 ::Sequence ( [
350
352
OpenSSL ::ASN1 ::Integer ( rsa1024 . n ) ,
351
353
OpenSSL ::ASN1 ::Integer ( rsa1024 . e )
352
354
] )
353
355
key = OpenSSL ::PKey ::RSA . new ( asn1 . to_der )
354
356
assert_not_predicate key , :private?
355
- assert_same_rsa dup_public ( rsa1024 ) , key
357
+ assert_same_rsa rsa1024pub , key
356
358
357
359
pem = <<~EOF
358
360
-----BEGIN RSA PUBLIC KEY-----
@@ -362,11 +364,13 @@ def test_RSAPublicKey
362
364
-----END RSA PUBLIC KEY-----
363
365
EOF
364
366
key = OpenSSL ::PKey ::RSA . new ( pem )
365
- assert_same_rsa dup_public ( rsa1024 ) , key
367
+ assert_same_rsa rsa1024pub , key
366
368
end
367
369
368
370
def test_PUBKEY
369
371
rsa1024 = Fixtures . pkey ( "rsa1024" )
372
+ rsa1024pub = OpenSSL ::PKey ::RSA . new ( rsa1024 . public_to_der )
373
+
370
374
asn1 = OpenSSL ::ASN1 ::Sequence ( [
371
375
OpenSSL ::ASN1 ::Sequence ( [
372
376
OpenSSL ::ASN1 ::ObjectId ( "rsaEncryption" ) ,
@@ -381,7 +385,7 @@ def test_PUBKEY
381
385
] )
382
386
key = OpenSSL ::PKey ::RSA . new ( asn1 . to_der )
383
387
assert_not_predicate key , :private?
384
- assert_same_rsa dup_public ( rsa1024 ) , key
388
+ assert_same_rsa rsa1024pub , key
385
389
386
390
pem = <<~EOF
387
391
-----BEGIN PUBLIC KEY-----
@@ -392,10 +396,15 @@ def test_PUBKEY
392
396
-----END PUBLIC KEY-----
393
397
EOF
394
398
key = OpenSSL ::PKey ::RSA . new ( pem )
395
- assert_same_rsa dup_public ( rsa1024 ) , key
399
+ assert_same_rsa rsa1024pub , key
400
+
401
+ assert_equal asn1 . to_der , key . to_der
402
+ assert_equal pem , key . export
396
403
397
- assert_equal asn1 . to_der , dup_public ( rsa1024 ) . to_der
398
- assert_equal pem , dup_public ( rsa1024 ) . export
404
+ assert_equal asn1 . to_der , rsa1024 . public_to_der
405
+ assert_equal asn1 . to_der , key . public_to_der
406
+ assert_equal pem , rsa1024 . public_to_pem
407
+ assert_equal pem , key . public_to_pem
399
408
end
400
409
401
410
def test_pem_passwd
@@ -482,12 +491,6 @@ def test_private_encoding_encrypted
482
491
assert_same_rsa rsa1024 , OpenSSL ::PKey . read ( pem , "abcdef" )
483
492
end
484
493
485
- def test_public_encoding
486
- rsa1024 = Fixtures . pkey ( "rsa1024" )
487
- assert_equal dup_public ( rsa1024 ) . to_der , rsa1024 . public_to_der
488
- assert_equal dup_public ( rsa1024 ) . to_pem , rsa1024 . public_to_pem
489
- end
490
-
491
494
def test_dup
492
495
key = Fixtures . pkey ( "rsa1024" )
493
496
key2 = key . dup
0 commit comments