aboutsummaryrefslogtreecommitdiffstats
path: root/ossl.c
diff options
context:
space:
mode:
authorMichal Rokos <m.rokos@sh.cvut.cz>2002-11-11 08:32:01 +0000
committerMichal Rokos <m.rokos@sh.cvut.cz>2002-11-11 08:32:01 +0000
commitf75c38e35604b7915a53062f7513cf5ad643aace (patch)
tree0bbfbb75baa9ee50bb2ae4b7eb1a28516df0ad67 /ossl.c
parent66e8833205f2f1888d98dfe576c4e36068c5dd34 (diff)
downloadruby-openssl-history-f75c38e35604b7915a53062f7513cf5ad643aace.tar.gz
BN: Make it work with Ruby's nums, PKCS7&X509: Fix for big serials
Diffstat (limited to 'ossl.c')
-rw-r--r--ossl.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/ossl.c b/ossl.c
index 6a70ec5..16650cb 100644
--- a/ossl.c
+++ b/ossl.c
@@ -81,6 +81,70 @@ time_to_time_t(VALUE time)
}
/*
+ * ASN1_INTEGER conversions
+ * TODO: Make a decision what's the right way to do this.
+ */
+VALUE
+asn1integer_to_num(ASN1_INTEGER *ai)
+{
+ BIGNUM *bn;
+ char *txt;
+ VALUE num;
+
+ if (!ai) {
+ ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
+ }
+ if (!(bn = ASN1_INTEGER_to_BN(ai, NULL))) {
+ ossl_raise(eOSSLError, "");
+ }
+#if 0
+ if (!(txt = BN_bn2dec(bn))) {
+ BN_free(bn);
+ ossl_raise(eOSSLError, "");
+ }
+ num = rb_cstr_to_inum(txt, 10, Qtrue);
+ OPENSSL_free(txt);
+#else
+ num = ossl_bn_new(bn);
+#endif
+ BN_free(bn);
+
+ return num;
+}
+
+#if 0
+ASN1_INTEGER *num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
+{
+ BIGNUM *bn = NULL;
+
+ if (RTEST(rb_obj_is_kind_of(obj, cBN))) {
+ bn = GetBNPtr(obj);
+ } else {
+ obj = rb_String(obj);
+ if (!BN_dec2bn(&bn, StringValuePtr(obj))) {
+ ossl_raise(eOSSLError, "");
+ }
+ }
+ if (!(ai = BN_to_ASN1_INTEGER(bn, ai))) {
+ BN_free(bn);
+ ossl_raise(eOSSLError, "");
+ }
+ BN_free(bn);
+ return ai;
+}
+#else
+ASN1_INTEGER *num_to_asn1integer(VALUE obj, ASN1_INTEGER *ai)
+{
+ BIGNUM *bn = GetBNPtr(obj);
+
+ if (!(ai = BN_to_ASN1_INTEGER(bn, ai))) {
+ ossl_raise(eOSSLError, "");
+ }
+ return ai;
+}
+#endif
+
+/*
* String to HEXString conversion
*/
int