Advertisement
Guest User

X509 with embedded X509, ruby problem patch

a guest
Feb 8th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.39 KB | None | 0 0
  1. diff --git a/ext/openssl/ossl_x509cert.c b/ext/openssl/ossl_x509cert.c
  2. index 80a0b76..0e602d1 100644
  3. --- a/ext/openssl/ossl_x509cert.c
  4. +++ b/ext/openssl/ossl_x509cert.c
  5. @@ -136,21 +136,35 @@ ossl_x509_initialize(int argc, VALUE *argv, VALUE self)
  6.  {
  7.      BIO *in;
  8.      X509 *x509, *x = DATA_PTR(self);
  9. -    VALUE arg;
  10. +    VALUE arg, argtype;
  11. +    int filetype = 0; // 0 not given, 1 PEM, 2 DER
  12.  
  13. -    if (rb_scan_args(argc, argv, "01", &arg) == 0) {
  14. +    rb_scan_args(argc, argv, "02", &arg, &argtype);
  15. +
  16. +    if (NIL_P(arg)) {
  17.         /* create just empty X509Cert */
  18.         return self;
  19.      }
  20. +
  21. +    if (TYPE(argtype) == T_STRING) {
  22. +        if (strcmp(StringValueCStr(argtype), "PEM") == 0) filetype = 1;
  23. +        if (strcmp(StringValueCStr(argtype), "DER") == 0) filetype = 2;
  24. +    }
  25. +
  26.      arg = ossl_to_der_if_possible(arg);
  27.      in = ossl_obj2bio(arg);
  28. -    x509 = PEM_read_bio_X509(in, &x, NULL, NULL);
  29. -    DATA_PTR(self) = x;
  30. -    if (!x509) {
  31. -       OSSL_BIO_reset(in);
  32. -       x509 = d2i_X509_bio(in, &x);
  33. -       DATA_PTR(self) = x;
  34. +
  35. +    if (NIL_P(argtype) || filetype == 1) {
  36. +        x509 = PEM_read_bio_X509(in, &x, NULL, NULL);
  37. +        DATA_PTR(self) = x;
  38. +    } else if (NIL_P(argtype) || filetype == 2) {
  39. +        if (!x509) {
  40. +           OSSL_BIO_reset(in);
  41. +           x509 = d2i_X509_bio(in, &x);
  42. +           DATA_PTR(self) = x;
  43. +        }
  44.      }
  45. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement