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;
}
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);
}
Aggregations