Search in sources :

Example 1 with ObjectAllocator

use of org.jruby.runtime.ObjectAllocator 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)

Aggregations

ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)1 ASN1String (org.bouncycastle.asn1.ASN1String)1 BEROctetString (org.bouncycastle.asn1.BEROctetString)1 DERBMPString (org.bouncycastle.asn1.DERBMPString)1 DERBitString (org.bouncycastle.asn1.DERBitString)1 DERGeneralString (org.bouncycastle.asn1.DERGeneralString)1 DERIA5String (org.bouncycastle.asn1.DERIA5String)1 DERNumericString (org.bouncycastle.asn1.DERNumericString)1 DEROctetString (org.bouncycastle.asn1.DEROctetString)1 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)1 DERT61String (org.bouncycastle.asn1.DERT61String)1 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)1 DERUniversalString (org.bouncycastle.asn1.DERUniversalString)1 DERVisibleString (org.bouncycastle.asn1.DERVisibleString)1 RubyArray (org.jruby.RubyArray)1 RubyClass (org.jruby.RubyClass)1 RubyModule (org.jruby.RubyModule)1 RubyString (org.jruby.RubyString)1 ObjectAllocator (org.jruby.runtime.ObjectAllocator)1 ThreadContext (org.jruby.runtime.ThreadContext)1