Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
- index 80a0b76..0e602d1 100644
- --- a/ext/openssl/ossl_x509cert.c
- +++ b/ext/openssl/ossl_x509cert.c
- @@ -136,21 +136,35 @@ ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
- {
- BIO *in;
- X509 *x509, *x = DATA_PTR(self);
- - VALUE arg;
- + VALUE arg, argtype;
- + int filetype = 0; // 0 not given, 1 PEM, 2 DER
- - if (rb_scan_args(argc, argv, "01", &arg) == 0) {
- + rb_scan_args(argc, argv, "02", &arg, &argtype);
- +
- + if (NIL_P(arg)) {
- /* create just empty X509Cert */
- return self;
- }
- +
- + if (TYPE(argtype) == T_STRING) {
- + if (strcmp(StringValueCStr(argtype), "PEM") == 0) filetype = 1;
- + if (strcmp(StringValueCStr(argtype), "DER") == 0) filetype = 2;
- + }
- +
- arg = ossl_to_der_if_possible(arg);
- in = ossl_obj2bio(arg);
- - x509 = PEM_read_bio_X509(in, &x, NULL, NULL);
- - DATA_PTR(self) = x;
- - if (!x509) {
- - OSSL_BIO_reset(in);
- - x509 = d2i_X509_bio(in, &x);
- - DATA_PTR(self) = x;
- +
- + if (NIL_P(argtype) || filetype == 1) {
- + x509 = PEM_read_bio_X509(in, &x, NULL, NULL);
- + DATA_PTR(self) = x;
- + } else if (NIL_P(argtype) || filetype == 2) {
- + if (!x509) {
- + OSSL_BIO_reset(in);
- + x509 = d2i_X509_bio(in, &x);
- + DATA_PTR(self) = x;
- + }
- }
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement