Search in sources :

Example 26 with RubyString

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

the class OCSPBasicResponse method add_nonce.

@JRubyMethod(name = "add_nonce", rest = true)
public OCSPBasicResponse add_nonce(IRubyObject[] args) {
    Ruby runtime = getRuntime();
    byte[] tmpNonce;
    if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0) {
        tmpNonce = generateNonce();
    } else {
        RubyString input = (RubyString) args[0];
        tmpNonce = input.getBytes();
    }
    extensions.add(new Extension(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, false, tmpNonce));
    nonce = tmpNonce;
    return this;
}
Also used : Extension(org.bouncycastle.asn1.x509.Extension) RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 27 with RubyString

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

the class OCSPCertificateId method issuer_name_hash.

@JRubyMethod(name = "issuer_name_hash")
public IRubyObject issuer_name_hash() {
    Ruby runtime = getRuntime();
    String oidSym = ASN1.oid2Sym(runtime, getBCCertificateID().getHashAlgOID());
    RubyString digestName = RubyString.newString(runtime, oidSym);
    // a hash of a hash if we don't have the original issuer around.
    if (originalIssuer == null) {
        try {
            return Digest.hexdigest(runtime.getCurrentContext(), this, digestName, RubyString.newString(runtime, bcCertId.getIssuerNameHash().getEncoded("DER")));
        } catch (IOException e) {
            throw newOCSPError(runtime, e);
        }
    } else {
        return Digest.hexdigest(runtime.getCurrentContext(), this, digestName, originalIssuer.getSubject().to_der(runtime.getCurrentContext()));
    }
}
Also used : RubyString(org.jruby.RubyString) RubyString(org.jruby.RubyString) IOException(java.io.IOException) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 28 with RubyString

use of org.jruby.RubyString in project nokogiri by sparklemotion.

the class XmlDocumentFragment method rbNew.

@JRubyMethod(name = "new", meta = true, required = 1, optional = 3)
public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args, Block block) {
    if (args.length < 1) {
        throw context.runtime.newArgumentError(args.length, 1);
    }
    if (!(args[0] instanceof XmlDocument)) {
        throw context.runtime.newArgumentError("first parameter must be a Nokogiri::XML::Document instance");
    }
    XmlDocument doc = (XmlDocument) args[0];
    // make wellformed fragment, ignore invalid namespace, or add appropriate namespace to parse
    if (args.length > 1 && args[1] instanceof RubyString) {
        final RubyString arg1 = (RubyString) args[1];
        if (XmlDocumentFragment.isTag(arg1)) {
            args[1] = RubyString.newString(context.runtime, addNamespaceDeclIfNeeded(doc, rubyStringToString(arg1)));
        }
    }
    XmlDocumentFragment fragment = (XmlDocumentFragment) NokogiriService.XML_DOCUMENT_FRAGMENT_ALLOCATOR.allocate(context.runtime, (RubyClass) cls);
    fragment.setDocument(context, doc);
    fragment.setNode(context.runtime, doc.getDocument().createDocumentFragment());
    Helpers.invoke(context, fragment, "initialize", args, block);
    return fragment;
}
Also used : RubyString(org.jruby.RubyString) JRubyClass(org.jruby.anno.JRubyClass) RubyClass(org.jruby.RubyClass) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 29 with RubyString

use of org.jruby.RubyString in project nokogiri by sparklemotion.

the class XmlNode method node_name_set.

@JRubyMethod(name = { "node_name=", "name=" })
public IRubyObject node_name_set(ThreadContext context, IRubyObject nodeName) {
    nodeName = doSetName(nodeName);
    String newName = nodeName == null ? null : rubyStringToString((RubyString) nodeName);
    this.node = NokogiriHelpers.renameNode(node, null, newName);
    return this;
}
Also used : RubyString(org.jruby.RubyString) RubyString(org.jruby.RubyString) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 30 with RubyString

use of org.jruby.RubyString in project nokogiri by sparklemotion.

the class NokogiriHelpers method nkf.

// This method is used from HTML documents. HTML meta tag with encoding specification
// might appear after non-ascii characters are used. For example, a title tag before
// a meta tag. In such a case, Xerces encodes characters in UTF-8 without seeing meta tag.
// Nokogiri uses NKF library to convert characters correct encoding. This means the method
// works only for JIS/Shift_JIS/EUC-JP.
private static CharSequence nkf(ThreadContext context, Charset encoding, CharSequence str) {
    final Ruby runtime = context.getRuntime();
    final ByteList opt;
    if (NokogiriHelpers.Shift_JIS.compareTo(encoding) == 0) {
        opt = _Sw;
    } else if (NokogiriHelpers.ISO_2022_JP.compareTo(encoding) == 0) {
        opt = _Jw;
    } else if (NokogiriHelpers.EUC_JP.compareTo(encoding) == 0) {
        opt = _Ew;
    } else // should not come here. should be treated before this method.
    {
        opt = _Ww;
    }
    Class<?> nkfClass;
    try {
        nkfClass = Ruby.getClassLoader().loadClass("org.jruby.ext.nkf.RubyNKF");
    } catch (ClassNotFoundException e1) {
        return str;
    }
    Method nkf_method;
    try {
        nkf_method = nkfClass.getMethod("nkf", ThreadContext.class, IRubyObject.class, IRubyObject.class, IRubyObject.class);
        RubyString r_str = (RubyString) nkf_method.invoke(null, context, null, runtime.newString(opt), runtime.newString(str.toString()));
        return NokogiriHelpers.rubyStringToString(r_str);
    } catch (SecurityException e) {
        return str;
    } catch (NoSuchMethodException e) {
        return str;
    } catch (IllegalArgumentException e) {
        return str;
    } catch (IllegalAccessException e) {
        return str;
    } catch (InvocationTargetException e) {
        return str;
    }
}
Also used : ByteList(org.jruby.util.ByteList) RubyString(org.jruby.RubyString) ThreadContext(org.jruby.runtime.ThreadContext) Method(java.lang.reflect.Method) IRubyObject(org.jruby.runtime.builtin.IRubyObject) InvocationTargetException(java.lang.reflect.InvocationTargetException) Ruby(org.jruby.Ruby)

Aggregations

RubyString (org.jruby.RubyString)49 JRubyMethod (org.jruby.anno.JRubyMethod)32 Ruby (org.jruby.Ruby)28 IRubyObject (org.jruby.runtime.builtin.IRubyObject)18 IOException (java.io.IOException)15 ByteList (org.jruby.util.ByteList)12 StringReader (java.io.StringReader)8 ByteArrayInputStream (java.io.ByteArrayInputStream)5 GeneralSecurityException (java.security.GeneralSecurityException)5 RaiseException (org.jruby.exceptions.RaiseException)5 BigInteger (java.math.BigInteger)4 PublicKey (java.security.PublicKey)4 NokogiriHelpers.rubyStringToString (nokogiri.internals.NokogiriHelpers.rubyStringToString)4 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 RubyArray (org.jruby.RubyArray)4 Charset (java.nio.charset.Charset)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 RubyInteger (org.jruby.RubyInteger)3 ThreadContext (org.jruby.runtime.ThreadContext)3 InputSource (org.xml.sax.InputSource)3