Skip to content

Commit

Permalink
Rename methods to match OpenSSL function names
Browse files Browse the repository at this point in the history
  • Loading branch information
sylph01 committed Jul 7, 2023
1 parent 4d67841 commit edadf2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,8 +1728,8 @@ Init_ossl_pkey(void)
rb_define_module_function(mPKey, "generate_parameters", ossl_pkey_s_generate_parameters, -1);
rb_define_module_function(mPKey, "generate_key", ossl_pkey_s_generate_key, -1);
#ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
rb_define_module_function(mPKey, "private_new", ossl_pkey_initialize_private, 2);
rb_define_module_function(mPKey, "public_new", ossl_pkey_initialize_public, 2);
rb_define_module_function(mPKey, "new_raw_private_key", ossl_pkey_initialize_private, 2);
rb_define_module_function(mPKey, "new_raw_public_key", ossl_pkey_initialize_public, 2);
#endif

rb_define_alloc_func(cPKey, ossl_pkey_alloc);
Expand All @@ -1745,12 +1745,12 @@ Init_ossl_pkey(void)
rb_define_method(cPKey, "private_to_der", ossl_pkey_private_to_der, -1);
rb_define_method(cPKey, "private_to_pem", ossl_pkey_private_to_pem, -1);
#ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
rb_define_method(cPKey, "private_to_raw", ossl_pkey_private_to_raw, 0);
rb_define_method(cPKey, "raw_private_key", ossl_pkey_private_to_raw, 0);
#endif
rb_define_method(cPKey, "public_to_der", ossl_pkey_public_to_der, 0);
rb_define_method(cPKey, "public_to_pem", ossl_pkey_public_to_pem, 0);
#ifdef HAVE_EVP_PKEY_NEW_RAW_PRIVATE_KEY
rb_define_method(cPKey, "public_to_raw", ossl_pkey_public_to_raw, 0);
rb_define_method(cPKey, "raw_public_key", ossl_pkey_public_to_raw, 0);
#endif
rb_define_method(cPKey, "compare?", ossl_pkey_compare, 1);

Expand Down
24 changes: 12 additions & 12 deletions test/openssl/test_pkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ def test_ed25519

begin
assert_equal "4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb",
priv.private_to_raw.unpack1("H*")
assert_equal OpenSSL::PKey.private_new("ED25519", priv.private_to_raw).private_to_pem,
priv.raw_private_key.unpack1("H*")
assert_equal OpenSSL::PKey.new_raw_private_key("ED25519", priv.raw_private_key).private_to_pem,
priv.private_to_pem
assert_equal "3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c",
priv.public_to_raw.unpack1("H*")
assert_equal OpenSSL::PKey.public_new("ED25519", priv.public_to_raw).public_to_pem,
priv.raw_public_key.unpack1("H*")
assert_equal OpenSSL::PKey.new_raw_public_key("ED25519", priv.raw_public_key).public_to_pem,
pub.public_to_pem
rescue NoMethodError
pend "running OpenSSL version does not have raw public key support"
Expand Down Expand Up @@ -169,10 +169,10 @@ def test_x25519
assert_equal bob_pem, bob.public_to_pem
assert_equal [shared_secret].pack("H*"), alice.derive(bob)
begin
alice_private = OpenSSL::PKey.private_new("X25519", alice.private_to_raw)
bob_public = OpenSSL::PKey.public_new("X25519", bob.public_to_raw)
alice_private_raw = alice.private_to_raw.unpack1("H*")
bob_public_raw = bob.public_to_raw.unpack1("H*")
alice_private = OpenSSL::PKey.new_raw_private_key("X25519", alice.raw_private_key)
bob_public = OpenSSL::PKey.new_raw_public_key("X25519", bob.raw_public_key)
alice_private_raw = alice.raw_private_key.unpack1("H*")
bob_public_raw = bob.raw_public_key.unpack1("H*")
rescue NoMethodError
# OpenSSL < 1.1.1
pend "running OpenSSL version does not have raw public key support"
Expand All @@ -190,10 +190,10 @@ def test_x25519
def raw_initialize
pend "Ed25519 is not implemented" unless OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10101000 && # >= v1.1.1

assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.private_new("foo123", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.private_new("ED25519", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.public_new("foo123", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.public_new("ED25519", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.new_raw_private_key("foo123", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.new_raw_private_key("ED25519", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.new_raw_public_key("foo123", "xxx") }
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.new_raw_public_key("ED25519", "xxx") }
end

def test_compare?
Expand Down

0 comments on commit edadf2f

Please sign in to comment.