@@ -1074,6 +1074,28 @@ ossl_pkey_compare(VALUE self, VALUE other)
10741074 ossl_raise (ePKeyError , "EVP_PKEY_eq" );
10751075}
10761076
1077+ /*
1078+ * call-seq:
1079+ * pkey.size -> integer
1080+ *
1081+ * Get the key size in bytes
1082+ *
1083+ * == Example
1084+ * rsa_key = OpenSSL::PKey::RSA.new(pem_encoded_private_key)
1085+ *
1086+ * rsa_key.size => 512
1087+ */
1088+ static VALUE
1089+ ossl_pkey_size (VALUE self ) {
1090+ int ret = 0 ;
1091+ EVP_PKEY * selfPKey ;
1092+
1093+ GetPKey (self , selfPKey );
1094+ ret = EVP_PKEY_get_size (selfPKey );
1095+
1096+ return INT2NUM (ret );
1097+ }
1098+
10771099/*
10781100 * call-seq:
10791101 * pkey.sign(digest, data [, options]) -> string
@@ -1760,6 +1782,7 @@ Init_ossl_pkey(void)
17601782 rb_define_method (cPKey , "raw_private_key" , ossl_pkey_raw_private_key , 0 );
17611783 rb_define_method (cPKey , "raw_public_key" , ossl_pkey_raw_public_key , 0 );
17621784 rb_define_method (cPKey , "compare?" , ossl_pkey_compare , 1 );
1785+ rb_define_method (cPKey , "size" , ossl_pkey_size , 0 );
17631786
17641787 rb_define_method (cPKey , "sign" , ossl_pkey_sign , -1 );
17651788 rb_define_method (cPKey , "verify" , ossl_pkey_verify , -1 );
0 commit comments