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;
}
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());
}
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;
}
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;
}
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;
}
Aggregations