Search in sources :

Example 56 with RubyArray

use of org.jruby.RubyArray in project jruby-openssl by jruby.

the class X509Extension method rawValueAsString.

private RubyString rawValueAsString(final ThreadContext context) throws IOException {
    final Ruby runtime = context.runtime;
    // e.g. [ ASN1::UTF8String, ... ]
    final IRubyObject value = getValue(runtime);
    if (value instanceof RubyArray) {
        final RubyArray arr = (RubyArray) value;
        final ByteList strVal = new ByteList(64);
        final int len = arr.size();
        for (int i = 0; i < len; i++) {
            IRubyObject entry = arr.eltInternal(i);
            if (entry.respondsTo("value")) {
                entry = entry.callMethod(context, "value");
            }
            strVal.append(entry.asString().getByteList());
            if (i < len - 1)
                strVal.append(',').append(' ');
        }
        return runtime.newString(strVal);
    }
    return value.asString();
}
Also used : ByteList(org.jruby.util.ByteList) RubyArray(org.jruby.RubyArray) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby)

Example 57 with RubyArray

use of org.jruby.RubyArray in project jruby-openssl by jruby.

the class X509Name method to_a.

@Override
@JRubyMethod
public RubyArray to_a() {
    final Ruby runtime = getRuntime();
    final RubyArray entries = runtime.newArray(oids.size());
    final Iterator<ASN1ObjectIdentifier> oidsIter = oids.iterator();
    @SuppressWarnings("unchecked") final Iterator<Object> valuesIter = (Iterator) values.iterator();
    final Iterator<RubyInteger> typesIter = types.iterator();
    while (oidsIter.hasNext()) {
        final ASN1ObjectIdentifier oid = oidsIter.next();
        String oName = name(runtime, oid);
        if (oName == null)
            oName = oid.toString();
        final String value = valuesIter.next().toString();
        final IRubyObject type = typesIter.next();
        final IRubyObject[] entry = new IRubyObject[] { runtime.newString(oName), runtime.newString(value), type };
        entries.append(runtime.newArrayNoCopy(entry));
    }
    return entries;
}
Also used : RubyArray(org.jruby.RubyArray) RubyInteger(org.jruby.RubyInteger) StringHelper.newString(org.jruby.ext.openssl.StringHelper.newString) RubyString(org.jruby.RubyString) ASN1String(org.bouncycastle.asn1.ASN1String) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Iterator(java.util.Iterator) ASN1Object(org.bouncycastle.asn1.ASN1Object) RubyObject(org.jruby.RubyObject) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 58 with RubyArray

use of org.jruby.RubyArray in project jruby-openssl by jruby.

the class X509Request method set_attributes.

@JRubyMethod(name = "attributes=")
public IRubyObject set_attributes(final ThreadContext context, final IRubyObject attributes) {
    this.attributes.clear();
    final RubyArray attrs = (RubyArray) attributes;
    for (int i = 0; i < attrs.size(); i++) {
        this.attributes.add((X509Attribute) attrs.entry(i));
    }
    if (request != null) {
        request.setAttributes(newAttributesImpl(context));
    }
    return attributes;
}
Also used : RubyArray(org.jruby.RubyArray) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 59 with RubyArray

use of org.jruby.RubyArray in project jruby-openssl by jruby.

the class PKCS7 method getAuxCerts.

private static List<X509AuxCertificate> getAuxCerts(final IRubyObject arg) {
    final RubyArray arr = (RubyArray) arg;
    List<X509AuxCertificate> certs = new ArrayList<X509AuxCertificate>(arr.size());
    for (int i = 0; i < arr.size(); i++) {
        certs.add(((X509Cert) arr.eltInternal(i)).getAuxCert());
    }
    return certs;
}
Also used : RubyArray(org.jruby.RubyArray) ArrayList(java.util.ArrayList) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate)

Example 60 with RubyArray

use of org.jruby.RubyArray in project jruby-openssl by jruby.

the class SSLContext method initFromCallback.

private void initFromCallback(final ThreadContext context) {
    final IRubyObject callback = getInstanceVariable("@client_cert_cb");
    if (callback != null && !callback.isNil()) {
        IRubyObject arr = callback.callMethod(context, "call", this);
        if (!(arr instanceof RubyArray)) {
            throw context.runtime.newTypeError("expected @client_cert_cb.call to return an Array but got: " + arr.getMetaClass().getName());
        }
        final IRubyObject cert = ((RubyArray) arr).entry(0);
        final IRubyObject key = ((RubyArray) arr).entry(1);
        if (!(cert instanceof X509Cert)) {
            throw context.runtime.newTypeError(cert.inspect() + " is not an instance of OpenSSL::X509::Certificate");
        }
        if (!(key instanceof PKey)) {
            throw context.runtime.newTypeError(key.inspect() + " is not an instance of OpenSSL::PKey::PKey");
        }
        t_cert = (X509Cert) cert;
        t_key = (PKey) key;
    }
}
Also used : RubyArray(org.jruby.RubyArray) IRubyObject(org.jruby.runtime.builtin.IRubyObject)

Aggregations

RubyArray (org.jruby.RubyArray)65 JRubyMethod (org.jruby.anno.JRubyMethod)34 Ruby (org.jruby.Ruby)26 IRubyObject (org.jruby.runtime.builtin.IRubyObject)26 NokogiriHelpers.nodeArrayToRubyArray (nokogiri.internals.NokogiriHelpers.nodeArrayToRubyArray)13 RubyString (org.jruby.RubyString)13 IOException (java.io.IOException)11 RaiseException (org.jruby.exceptions.RaiseException)10 ArrayList (java.util.ArrayList)8 X509AuxCertificate (org.jruby.ext.openssl.x509store.X509AuxCertificate)8 RubyClass (org.jruby.RubyClass)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)5 RubyFixnum (org.jruby.RubyFixnum)5 ThreadContext (org.jruby.runtime.ThreadContext)5 NokogiriHelpers.clearCachedNode (nokogiri.internals.NokogiriHelpers.clearCachedNode)4 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 ASN1String (org.bouncycastle.asn1.ASN1String)4 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)4 RubyModule (org.jruby.RubyModule)4