diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-08 15:31:29 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2016-12-23 13:14:09 +0900 |
commit | 95a500a72917bb7eccf60a96da68fa938cef8f69 (patch) | |
tree | 69cc599462df4cfec0af5419965e6b4930743abd /ext/openssl | |
parent | faaa3021385b5432dc960dfc8ca55d1b2fc89d3b (diff) | |
download | ruby-openssl-topic/bn-updates.tar.gz |
bn: implement OpenSSL::BN#negative?topic/bn-updates
Numeric class implemented #negative? and #positive? in Ruby 2.3. Let's
follow that.
Diffstat (limited to 'ext/openssl')
-rw-r--r-- | ext/openssl/ossl_bn.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index 1afebf44..dfe1b268 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -377,6 +377,21 @@ BIGNUM_BOOL1(is_one) */ BIGNUM_BOOL1(is_odd) +/* + * call-seq: + * bn.negative? => true | false + */ +static VALUE +ossl_bn_is_negative(VALUE self) +{ + BIGNUM *bn; + + GetBN(self, bn); + if (BN_is_zero(bn)) + return Qfalse; + return BN_is_negative(bn) ? Qtrue : Qfalse; +} + #define BIGNUM_1c(func) \ static VALUE \ ossl_bn_##func(VALUE self) \ @@ -1135,6 +1150,7 @@ Init_ossl_bn(void) rb_define_method(cBN, "one?", ossl_bn_is_one, 0); /* is_word */ rb_define_method(cBN, "odd?", ossl_bn_is_odd, 0); + rb_define_method(cBN, "negative?", ossl_bn_is_negative, 0); /* zero * one |