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