Search in sources :

Example 16 with RubyArray

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

the class Cipher method ciphers.

@JRubyMethod(meta = true)
public static IRubyObject ciphers(final ThreadContext context, final IRubyObject self) {
    final Ruby runtime = context.runtime;
    final Collection<String> ciphers = Algorithm.allSupportedCiphers().keySet();
    final RubyArray result = runtime.newArray(ciphers.size() * 2);
    for (final String cipher : ciphers) {
        // upper-case
        result.append(runtime.newString(cipher));
    }
    for (final String cipher : ciphers) {
        // than lower-case OpenSSL compatibility
        result.append(runtime.newString(cipher.toLowerCase()));
    }
    return result;
}
Also used : RubyArray(org.jruby.RubyArray) RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 17 with RubyArray

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

the class ASN1 method createASN1.

public static void createASN1(final Ruby runtime, final RubyModule OpenSSL) {
    final RubyModule ASN1 = OpenSSL.defineModuleUnder("ASN1");
    final RubyClass OpenSSLError = OpenSSL.getClass("OpenSSLError");
    ASN1.defineClassUnder("ASN1Error", OpenSSLError, OpenSSLError.getAllocator());
    ASN1.defineAnnotatedMethods(ASN1.class);
    final RubyArray UNIVERSAL_TAG_NAME = runtime.newArray(ASN1_INFO.length);
    for (int i = 0; i < ASN1_INFO.length; i++) {
        final String name = (String) ASN1_INFO[i][0];
        if (name.charAt(0) != '[') {
            UNIVERSAL_TAG_NAME.append(runtime.newString(name));
            ASN1.setConstant(name, runtime.newFixnum(i));
        } else {
            UNIVERSAL_TAG_NAME.append(runtime.getNil());
        }
    }
    ASN1.setConstant("UNIVERSAL_TAG_NAME", UNIVERSAL_TAG_NAME);
    final ThreadContext context = runtime.getCurrentContext();
    final ObjectAllocator asn1DataAllocator = ASN1Data.ALLOCATOR;
    RubyClass _ASN1Data = ASN1.defineClassUnder("ASN1Data", runtime.getObject(), asn1DataAllocator);
    _ASN1Data.addReadWriteAttribute(context, "value");
    _ASN1Data.addReadWriteAttribute(context, "tag");
    _ASN1Data.addReadWriteAttribute(context, "tag_class");
    _ASN1Data.defineAnnotatedMethods(ASN1Data.class);
    final ObjectAllocator primitiveAllocator = Primitive.ALLOCATOR;
    RubyClass Primitive = ASN1.defineClassUnder("Primitive", _ASN1Data, primitiveAllocator);
    Primitive.addReadWriteAttribute(context, "tagging");
    Primitive.addReadAttribute(context, "infinite_length");
    Primitive.defineAnnotatedMethods(Primitive.class);
    final ObjectAllocator constructiveAllocator = Constructive.ALLOCATOR;
    RubyClass Constructive = ASN1.defineClassUnder("Constructive", _ASN1Data, constructiveAllocator);
    Constructive.includeModule(runtime.getModule("Enumerable"));
    Constructive.addReadWriteAttribute(context, "tagging");
    Constructive.addReadWriteAttribute(context, "infinite_length");
    Constructive.defineAnnotatedMethods(Constructive.class);
    // OpenSSL::ASN1::Boolean <=> value is a Boolean
    ASN1.defineClassUnder("Boolean", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::Integer <=> value is a Number
    ASN1.defineClassUnder("Integer", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::Null <=> value is always nil
    ASN1.defineClassUnder("Null", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::Object <=> value is a String
    ASN1.defineClassUnder("Object", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::Enumerated <=> value is a Number
    ASN1.defineClassUnder("Enumerated", Primitive, primitiveAllocator);
    RubyClass BitString = ASN1.defineClassUnder("BitString", Primitive, primitiveAllocator);
    BitString.addReadWriteAttribute(context, "unused_bits");
    ASN1.defineClassUnder("OctetString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("UTF8String", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("NumericString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("PrintableString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("T61String", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("VideotexString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("IA5String", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("GraphicString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("ISO64String", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("GeneralString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("UniversalString", Primitive, primitiveAllocator);
    ASN1.defineClassUnder("BMPString", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::UTCTime <=> value is a Time
    ASN1.defineClassUnder("UTCTime", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::GeneralizedTime <=> value is a Time
    ASN1.defineClassUnder("GeneralizedTime", Primitive, primitiveAllocator);
    // OpenSSL::ASN1::EndOfContent <=> value is always nil
    ASN1.defineClassUnder("EndOfContent", Primitive, primitiveAllocator);
    RubyClass ObjectId = ASN1.defineClassUnder("ObjectId", Primitive, primitiveAllocator);
    ObjectId.defineAnnotatedMethods(ObjectId.class);
    ASN1.defineClassUnder("Sequence", Constructive, Constructive.getAllocator());
    ASN1.defineClassUnder("Set", Constructive, Constructive.getAllocator());
}
Also used : RubyModule(org.jruby.RubyModule) RubyArray(org.jruby.RubyArray) ThreadContext(org.jruby.runtime.ThreadContext) RubyClass(org.jruby.RubyClass) DERBitString(org.bouncycastle.asn1.DERBitString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERBMPString(org.bouncycastle.asn1.DERBMPString) DERGeneralString(org.bouncycastle.asn1.DERGeneralString) RubyString(org.jruby.RubyString) DERPrintableString(org.bouncycastle.asn1.DERPrintableString) DERNumericString(org.bouncycastle.asn1.DERNumericString) DEROctetString(org.bouncycastle.asn1.DEROctetString) BEROctetString(org.bouncycastle.asn1.BEROctetString) DERIA5String(org.bouncycastle.asn1.DERIA5String) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERT61String(org.bouncycastle.asn1.DERT61String) DERVisibleString(org.bouncycastle.asn1.DERVisibleString) ASN1String(org.bouncycastle.asn1.ASN1String) DERUniversalString(org.bouncycastle.asn1.DERUniversalString) ObjectAllocator(org.jruby.runtime.ObjectAllocator)

Example 18 with RubyArray

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

the class PKCS7 method signers.

/**
 * ossl_pkcs7_get_signer
 *
 * This seems to return a list of SignerInfo objects.
 */
@JRubyMethod
public IRubyObject signers() {
    Collection<SignerInfoWithPkey> signerInfos = p7.getSignerInfo();
    RubyArray ary = getRuntime().newArray(signerInfos.size());
    for (SignerInfoWithPkey signerInfo : signerInfos) {
        ary.append(SignerInfo.create(getRuntime(), signerInfo));
    }
    return ary;
}
Also used : SignerInfoWithPkey(org.jruby.ext.openssl.impl.SignerInfoWithPkey) RubyArray(org.jruby.RubyArray) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 19 with RubyArray

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

the class PKCS7 method recipients.

@JRubyMethod
public IRubyObject recipients() {
    Collection<RecipInfo> sk;
    if (p7.isEnveloped()) {
        sk = p7.getEnveloped().getRecipientInfo();
    } else if (p7.isSignedAndEnveloped()) {
        sk = p7.getSignedAndEnveloped().getRecipientInfo();
    } else {
        sk = null;
    }
    if (sk == null) {
        return getRuntime().newArray();
    }
    RubyArray ary = getRuntime().newArray(sk.size());
    for (RecipInfo ri : sk) {
        ary.append(RecipientInfo.create(getRuntime(), ri));
    }
    return ary;
}
Also used : RecipInfo(org.jruby.ext.openssl.impl.RecipInfo) RubyArray(org.jruby.RubyArray) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 20 with RubyArray

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

the class PKeyEC method builtin_curves.

@JRubyMethod(meta = true)
public static RubyArray builtin_curves(ThreadContext context, IRubyObject self) {
    final Ruby runtime = context.runtime;
    final RubyArray curves = runtime.newArray();
    Enumeration names;
    names = org.bouncycastle.asn1.x9.X962NamedCurves.getNames();
    while (names.hasMoreElements()) {
        final String name = (String) names.nextElement();
        RubyString desc;
        if (name.startsWith("prime")) {
            desc = RubyString.newString(runtime, "X9.62 curve over a xxx bit prime field");
        } else {
            desc = RubyString.newString(runtime, "X9.62 curve over a xxx bit binary field");
        }
        curves.append(RubyArray.newArrayNoCopy(runtime, new IRubyObject[] { RubyString.newString(runtime, name), desc }));
    }
    names = org.bouncycastle.asn1.sec.SECNamedCurves.getNames();
    while (names.hasMoreElements()) {
        RubyString name = RubyString.newString(runtime, (String) names.nextElement());
        RubyString desc = RubyString.newString(runtime, "SECG curve over a xxx bit binary field");
        curves.append(RubyArray.newArrayNoCopy(runtime, new IRubyObject[] { name, desc }));
    }
    names = org.bouncycastle.asn1.nist.NISTNamedCurves.getNames();
    while (names.hasMoreElements()) {
        RubyString name = RubyString.newString(runtime, (String) names.nextElement());
        IRubyObject[] nameAndDesc = new IRubyObject[] { name, RubyString.newEmptyString(runtime) };
        curves.append(RubyArray.newArrayNoCopy(runtime, nameAndDesc));
    }
    names = org.bouncycastle.asn1.teletrust.TeleTrusTNamedCurves.getNames();
    while (names.hasMoreElements()) {
        RubyString name = RubyString.newString(runtime, (String) names.nextElement());
        RubyString desc = RubyString.newString(runtime, "RFC 5639 curve over a xxx bit prime field");
        curves.append(RubyArray.newArrayNoCopy(runtime, new IRubyObject[] { name, desc }));
    }
    return curves;
}
Also used : Enumeration(java.util.Enumeration) RubyArray(org.jruby.RubyArray) RubyString(org.jruby.RubyString) RubyString(org.jruby.RubyString) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

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