Search in sources :

Example 1 with BlockCallback

use of org.jruby.runtime.BlockCallback in project jruby-openssl by jruby.

the class SSLContext method convertToAuxCerts.

private static List<X509AuxCertificate> convertToAuxCerts(final ThreadContext context, IRubyObject value) {
    final RubyModule SSLContext = _SSLContext(context.runtime);
    final RubyModule Certificate = _Certificate(context.runtime);
    if (value instanceof RubyArray) {
        final RubyArray val = (RubyArray) value;
        final int size = val.size();
        final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>(size);
        for (int i = 0; i < size; i++) result.add(assureCertificate(context, Certificate, val.eltInternal(i)).getAuxCert());
        return result;
    }
    if (value instanceof List) {
        final List<X509Cert> val = (List) value;
        final int size = val.size();
        final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>(size);
        for (int i = 0; i < size; i++) result.add(assureCertificate(context, Certificate, val.get(i)).getAuxCert());
        return result;
    }
    // else :
    final ArrayList<X509AuxCertificate> result = new ArrayList<X509AuxCertificate>();
    Utils.invoke(context, value, "each", CallBlock.newCallClosure(value, SSLContext, Arity.NO_ARGUMENTS, new BlockCallback() {

        public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
            result.add(assureCertificate(context, Certificate, args[0]).getAuxCert());
            return context.nil;
        }
    }, context));
    return result;
}
Also used : RubyModule(org.jruby.RubyModule) RubyArray(org.jruby.RubyArray) ArrayList(java.util.ArrayList) BlockCallback(org.jruby.runtime.BlockCallback) ThreadContext(org.jruby.runtime.ThreadContext) Block(org.jruby.runtime.Block) CallBlock(org.jruby.runtime.CallBlock) ByteList(org.jruby.util.ByteList) List(java.util.List) ArrayList(java.util.ArrayList) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 RubyArray (org.jruby.RubyArray)1 RubyModule (org.jruby.RubyModule)1 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)1 Block (org.jruby.runtime.Block)1 BlockCallback (org.jruby.runtime.BlockCallback)1 CallBlock (org.jruby.runtime.CallBlock)1 ThreadContext (org.jruby.runtime.ThreadContext)1 ByteList (org.jruby.util.ByteList)1