use of org.jruby.RubyString in project jruby-openssl by jruby.
the class BN method coerce.
@JRubyMethod(name = "coerce")
public // FIXME: is this right? don't see how it would be useful...
IRubyObject coerce(IRubyObject other) {
final Ruby runtime = getRuntime();
IRubyObject self;
if (other instanceof RubyString) {
self = runtime.newString(value.toString());
} else if (other instanceof RubyInteger) {
self = to_i();
} else if (other instanceof BN) {
self = this;
} else {
throw runtime.newTypeError("don't know how to coerce to " + other.getMetaClass().getName());
}
return runtime.newArray(other, self);
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class Cipher method set_auth_tag.
@JRubyMethod(name = "auth_tag=")
public IRubyObject set_auth_tag(final ThreadContext context, final IRubyObject tag) {
if (!isAuthDataMode()) {
throw newCipherError(context.runtime, "authentication tag not supported by this cipher");
}
final RubyString auth_tag = tag.asString();
this.auth_tag = StringHelper.setByteListShared(auth_tag);
return auth_tag;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class NetscapeSPKI method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;
if (args.length > 0) {
byte[] request = args[0].convertToString().getBytes();
request = tryBase64Decode(request);
final NetscapeCertRequest cert;
try {
this.cert = cert = new NetscapeCertRequest(request);
challenge = runtime.newString(cert.getChallenge());
} catch (GeneralSecurityException e) {
throw newSPKIError(e);
} catch (IllegalArgumentException e) {
throw newSPKIError(e);
}
final PublicKey publicKey = cert.getPublicKey();
final String algorithm = publicKey.getAlgorithm();
final RubyString pub_key = RubyString.newString(runtime, publicKey.getEncoded());
if ("RSA".equalsIgnoreCase(algorithm)) {
this.public_key = _RSA(runtime).callMethod(context, "new", pub_key);
} else if ("DSA".equalsIgnoreCase(algorithm)) {
this.public_key = _DSA(runtime).callMethod(context, "new", pub_key);
} else {
throw runtime.newLoadError("not implemented algo for public key: " + algorithm);
}
}
return this;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class OCSPCertificateId method issuer_key_hash.
// For whatever reason, the MRI Ruby tests appear to suggest that they compute the hexdigest hash
// of the issuer key over the original key instead of the hash computed in the created CertID.
// I'm not sure how it's supposed to work with a passed in DER string since presumably the hash
// is already computed and can't be reversed to get to the original key, so we just compute
// a hash of a hash if we don't have the original issuer around.
@JRubyMethod(name = "issuer_key_hash")
public IRubyObject issuer_key_hash() {
Ruby runtime = getRuntime();
String oidSym = ASN1.oid2Sym(runtime, getBCCertificateID().getHashAlgOID());
RubyString digestName = RubyString.newString(runtime, oidSym);
if (originalIssuer == null) {
try {
return Digest.hexdigest(runtime.getCurrentContext(), this, RubyString.newString(runtime, oidSym), RubyString.newString(runtime, bcCertId.getIssuerKeyHash().getEncoded("DER")));
} catch (IOException e) {
throw newOCSPError(runtime, e);
}
} else {
PKey key = (PKey) originalIssuer.public_key(runtime.getCurrentContext());
return Digest.hexdigest(runtime.getCurrentContext(), this, digestName, key.to_der());
}
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class X509Extension method to_s.
// "oid = critical, value"
@JRubyMethod
public RubyString to_s(final ThreadContext context) {
final Ruby runtime = context.runtime;
final RubyString str = RubyString.newString(runtime, oidSym(runtime));
str.getByteList().append(' ').append('=').append(' ');
if (isRealCritical())
str.getByteList().append(critical__);
// self.value.gsub(/\n/, ", ")
final RubyString value = value(context);
value.callMethod(context, "gsub!", new IRubyObject[] { RubyString.newStringShared(runtime, StringHelper.NEW_LINE), RubyString.newStringShared(runtime, StringHelper.COMMA_SPACE) });
str.getByteList().append(value.getByteList());
return str;
}
Aggregations