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