aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-12-08 15:31:29 +0900
committerKazuki Yamaguchi <k@rhe.jp>2016-12-23 13:14:09 +0900
commit95a500a72917bb7eccf60a96da68fa938cef8f69 (patch)
tree69cc599462df4cfec0af5419965e6b4930743abd /ext/openssl
parentfaaa3021385b5432dc960dfc8ca55d1b2fc89d3b (diff)
downloadruby-openssl-95a500a72917bb7eccf60a96da68fa938cef8f69.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.c16
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