Search in sources :

Example 1 with SMIME

use of org.jruby.ext.openssl.impl.SMIME in project jruby-openssl by jruby.

the class PKCS7 method read_smime.

@JRubyMethod(meta = true)
public static IRubyObject read_smime(IRubyObject self, IRubyObject arg) {
    final Ruby runtime = self.getRuntime();
    final BIO in = obj2bio(arg);
    final BIO[] out = new BIO[] { null };
    org.jruby.ext.openssl.impl.PKCS7 pkcs7Impl = null;
    try {
        pkcs7Impl = new SMIME(Mime.DEFAULT).readPKCS7(in, out);
    } catch (IOException ioe) {
        throw newPKCS7Error(runtime, ioe.getMessage());
    } catch (PKCS7Exception pkcs7e) {
        throw newPKCS7Error(runtime, pkcs7e);
    }
    if (pkcs7Impl == null) {
        throw newPKCS7Error(runtime, (String) null);
    }
    IRubyObject data = out[0] != null ? membio2str(runtime, out[0]) : runtime.getNil();
    final PKCS7 pkcs7 = wrap(runtime, pkcs7Impl);
    pkcs7.setData(data);
    return pkcs7;
}
Also used : ThreadContext(org.jruby.runtime.ThreadContext) SMIME(org.jruby.ext.openssl.impl.SMIME) MemBIO(org.jruby.ext.openssl.impl.MemBIO) BIO(org.jruby.ext.openssl.impl.BIO) IOException(java.io.IOException) PKCS7Exception(org.jruby.ext.openssl.impl.PKCS7Exception) NotVerifiedPKCS7Exception(org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 2 with SMIME

use of org.jruby.ext.openssl.impl.SMIME in project jruby-openssl by jruby.

the class PKCS7 method write_smime.

@JRubyMethod(meta = true, rest = true)
public static IRubyObject write_smime(IRubyObject self, IRubyObject[] args) {
    final Ruby runtime = self.getRuntime();
    final PKCS7 pkcs7;
    IRubyObject data = runtime.getNil();
    IRubyObject flags = runtime.getNil();
    switch(Arity.checkArgumentCount(runtime, args, 1, 3)) {
        case 3:
            flags = args[2];
        case 2:
            data = args[1];
        default:
            pkcs7 = (PKCS7) args[0];
    }
    if (data.isNil())
        data = pkcs7.getData();
    final int flg = flags.isNil() ? 0 : RubyNumeric.fix2int(flags);
    String smime = "";
    try {
        smime = new SMIME().writePKCS7(pkcs7.p7, data.asJavaString(), flg);
    } catch (PKCS7Exception e) {
        throw newPKCS7Error(runtime, e);
    } catch (IOException e) {
        throw newPKCS7Error(runtime, e.getMessage());
    }
    return RubyString.newString(runtime, smime);
}
Also used : SMIME(org.jruby.ext.openssl.impl.SMIME) RubyString(org.jruby.RubyString) IOException(java.io.IOException) IRubyObject(org.jruby.runtime.builtin.IRubyObject) PKCS7Exception(org.jruby.ext.openssl.impl.PKCS7Exception) NotVerifiedPKCS7Exception(org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Aggregations

IOException (java.io.IOException)2 Ruby (org.jruby.Ruby)2 JRubyMethod (org.jruby.anno.JRubyMethod)2 NotVerifiedPKCS7Exception (org.jruby.ext.openssl.impl.NotVerifiedPKCS7Exception)2 PKCS7Exception (org.jruby.ext.openssl.impl.PKCS7Exception)2 SMIME (org.jruby.ext.openssl.impl.SMIME)2 IRubyObject (org.jruby.runtime.builtin.IRubyObject)2 RubyString (org.jruby.RubyString)1 BIO (org.jruby.ext.openssl.impl.BIO)1 MemBIO (org.jruby.ext.openssl.impl.MemBIO)1 ThreadContext (org.jruby.runtime.ThreadContext)1