ruby-changes:43024
From: rhe <ko1@a...>
Date: Sat, 21 May 2016 14:30:54 +0900 (JST)
Subject: [ruby-changes:43024] rhe:r55098 (trunk): openssl: add OpenSSL::PKey::EC#private? and #public?
rhe 2016-05-21 14:30:48 +0900 (Sat, 21 May 2016) New Revision: 55098 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55098 Log: openssl: add OpenSSL::PKey::EC#private? and #public? * ext/openssl/ossl_pkey_ec.c: rename PKey::EC#private_key? and #public_key? to #private? and #public? for consistency with other PKey types. Old names remain as alias. [ruby-core:45541] [Bug #6567] * test/openssl/test_pkey_ec.rb (test_check_key): check private? and public? works correctly. Modified files: trunk/ChangeLog trunk/ext/openssl/ossl_pkey_ec.c trunk/test/openssl/test_pkey_ec.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 55097) +++ ChangeLog (revision 55098) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat May 21 14:25:38 2016 Kazuki Yamaguchi <k@r...> + + * ext/openssl/ossl_pkey_ec.c: rename PKey::EC#private_key? and + #public_key? to #private? and #public? for consistency with other + PKey types. Old names remain as alias. [ruby-core:45541] [Bug #6567] + + * test/openssl/test_pkey_ec.rb (test_check_key): check private? and + public? works correctly. + Sat May 21 12:40:36 2016 Kazuki Yamaguchi <k@r...> * ext/openssl/lib/openssl/buffering.rb (read_nonblock, readpartial): Index: test/openssl/test_pkey_ec.rb =================================================================== --- test/openssl/test_pkey_ec.rb (revision 55097) +++ test/openssl/test_pkey_ec.rb (revision 55098) @@ -40,9 +40,21 @@ class OpenSSL::TestEC < OpenSSL::TestCas https://github.com/ruby/ruby/blob/trunk/test/openssl/test_pkey_ec.rb#L40 def test_check_key for key in @keys - assert_equal(key.check_key, true) - assert_equal(key.private_key?, true) - assert_equal(key.public_key?, true) + assert_equal(true, key.check_key) + assert_equal(true, key.private?) + assert_equal(true, key.public?) + key2 = OpenSSL::PKey::EC.new(key.group) + assert_equal(false, key2.private?) + assert_equal(false, key2.public?) + key2.public_key = key.public_key + assert_equal(false, key2.private?) + assert_equal(true, key2.public?) + key2.private_key = key.private_key + assert_equal(true, key2.private?) + assert_equal(true, key2.public?) + assert_equal(true, key2.check_key) + key2.private_key += 1 + assert_raise(OpenSSL::PKey::ECError) { key2.check_key } end end Index: ext/openssl/ossl_pkey_ec.c =================================================================== --- ext/openssl/ossl_pkey_ec.c (revision 55097) +++ ext/openssl/ossl_pkey_ec.c (revision 55098) @@ -438,32 +438,34 @@ static VALUE ossl_ec_key_set_public_key( https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_ec.c#L438 /* * call-seq: - * key.public_key? => true or false + * key.public? => true or false * - * Both public_key? and private_key? may return false at the same time unlike other PKey classes. + * Returns whether this EC instance has a public key. The public key + * (EC::Point) can be retrieved with EC#public_key. */ -static VALUE ossl_ec_key_is_public_key(VALUE self) +static VALUE ossl_ec_key_is_public(VALUE self) { EC_KEY *ec; Require_EC_KEY(self, ec); - return (EC_KEY_get0_public_key(ec) ? Qtrue : Qfalse); + return EC_KEY_get0_public_key(ec) ? Qtrue : Qfalse; } /* * call-seq: - * key.private_key? => true or false + * key.private? => true or false * - * Both public_key? and private_key? may return false at the same time unlike other PKey classes. + * Returns whether this EC instance has a private key. The private key (BN) can + * be retrieved with EC#private_key. */ -static VALUE ossl_ec_key_is_private_key(VALUE self) +static VALUE ossl_ec_key_is_private(VALUE self) { EC_KEY *ec; Require_EC_KEY(self, ec); - return (EC_KEY_get0_private_key(ec) ? Qtrue : Qfalse); + return EC_KEY_get0_private_key(ec) ? Qtrue : Qfalse; } static VALUE ossl_ec_key_to_string(VALUE self, VALUE ciph, VALUE pass, int format) @@ -1619,8 +1621,10 @@ void Init_ossl_ec(void) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_ec.c#L1621 rb_define_method(cEC, "private_key=", ossl_ec_key_set_private_key, 1); rb_define_method(cEC, "public_key", ossl_ec_key_get_public_key, 0); rb_define_method(cEC, "public_key=", ossl_ec_key_set_public_key, 1); - rb_define_method(cEC, "private_key?", ossl_ec_key_is_private_key, 0); - rb_define_method(cEC, "public_key?", ossl_ec_key_is_public_key, 0); + rb_define_method(cEC, "private?", ossl_ec_key_is_private, 0); + rb_define_method(cEC, "public?", ossl_ec_key_is_public, 0); + rb_define_alias(cEC, "private_key?", "private?"); + rb_define_alias(cEC, "public_key?", "public?"); /* rb_define_method(cEC, "", ossl_ec_key_get_, 0); rb_define_method(cEC, "=", ossl_ec_key_set_ 1); set/get enc_flags -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/