Search in sources :

Example 36 with RubyString

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);
}
Also used : RubyInteger(org.jruby.RubyInteger) RubyString(org.jruby.RubyString) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 37 with RubyString

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;
}
Also used : RubyString(org.jruby.RubyString) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 38 with RubyString

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;
}
Also used : NetscapeCertRequest(org.jruby.ext.openssl.impl.NetscapeCertRequest) PublicKey(java.security.PublicKey) GeneralSecurityException(java.security.GeneralSecurityException) RubyString(org.jruby.RubyString) DERBitString(org.bouncycastle.asn1.DERBitString) DERIA5String(org.bouncycastle.asn1.DERIA5String) RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 39 with RubyString

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());
    }
}
Also used : RubyString(org.jruby.RubyString) RubyString(org.jruby.RubyString) IOException(java.io.IOException) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 40 with RubyString

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;
}
Also used : RubyString(org.jruby.RubyString) Ruby(org.jruby.Ruby) JRubyMethod(org.jruby.anno.JRubyMethod)

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