use of org.jruby.ext.openssl.impl.PKCS7Exception 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.PKCS7Exception in project jruby-openssl by jruby.
the class PKCS7 method add_signer.
@JRubyMethod
public IRubyObject add_signer(IRubyObject obj) {
SignerInfoWithPkey signedInfo = ((SignerInfo) obj).getSignerInfo().dup();
try {
p7.addSigner(signedInfo);
} catch (PKCS7Exception e) {
throw newPKCS7Error(getRuntime(), e);
}
if (p7.isSigned()) {
ASN1Encodable objectId = org.jruby.ext.openssl.impl.PKCS7.OID_pkcs7_data;
signedInfo.addSignedAttribute(ASN1Registry.NID_pkcs9_contentType, objectId);
}
return this;
}
use of org.jruby.ext.openssl.impl.PKCS7Exception 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);
}
use of org.jruby.ext.openssl.impl.PKCS7Exception in project jruby-openssl by jruby.
the class PKCS7 method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
if (Arity.checkArgumentCount(getRuntime(), args, 0, 1) == 0) {
p7 = new org.jruby.ext.openssl.impl.PKCS7();
try {
p7.setType(ASN1Registry.NID_undef);
} catch (PKCS7Exception e) {
throw newPKCS7Error(getRuntime(), e);
}
return this;
}
IRubyObject arg = to_der_if_possible(context, args[0]);
BIO input = obj2bio(arg);
try {
p7 = org.jruby.ext.openssl.impl.PKCS7.readPEM(input);
if (p7 == null) {
input.reset();
p7 = org.jruby.ext.openssl.impl.PKCS7.fromASN1(input);
}
} catch (IllegalArgumentException e) {
throw getRuntime().newArgumentError(e.getMessage());
} catch (IOException ioe) {
throw newPKCS7Error(getRuntime(), ioe.getMessage());
} catch (PKCS7Exception pkcs7e) {
throw newPKCS7Error(getRuntime(), pkcs7e);
}
setData(getRuntime().getNil());
return this;
}
use of org.jruby.ext.openssl.impl.PKCS7Exception in project jruby-openssl by jruby.
the class PKCS7 method decrypt.
@JRubyMethod(rest = true)
public IRubyObject decrypt(IRubyObject[] args) {
IRubyObject dflags;
if (Arity.checkArgumentCount(getRuntime(), args, 2, 3) == 3) {
dflags = args[2];
} else {
dflags = getRuntime().getNil();
}
PKey pkey = (PKey) args[0];
X509Cert cert = (X509Cert) args[1];
final PrivateKey privKey = pkey.getPrivateKey();
final X509AuxCertificate auxCert = cert.getAuxCert();
final int flg = dflags.isNil() ? 0 : RubyNumeric.fix2int(dflags);
final BIO out = BIO.mem();
try {
p7.decrypt(privKey, auxCert, out, flg);
} catch (PKCS7Exception pkcs7e) {
throw newPKCS7Error(getRuntime(), pkcs7e);
}
return membio2str(getRuntime(), out);
}
Aggregations