use of org.jruby.RubyString in project jruby-openssl by jruby.
the class X509Request 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 (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
return this;
try {
request = new PKCS10Request(StringHelper.readX509PEM(context, args[0]));
} catch (RuntimeException e) {
debugStackTrace(runtime, e);
throw newRequestError(runtime, "invalid certificate request data", e);
}
final String algorithm;
final byte[] encoded;
try {
final PublicKey pkey = request.generatePublicKey();
algorithm = pkey.getAlgorithm();
encoded = pkey.getEncoded();
} catch (IOException e) {
throw newRequestError(runtime, e);
} catch (GeneralSecurityException e) {
throw newRequestError(runtime, e);
}
final RubyString enc = RubyString.newString(runtime, encoded);
if ("RSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "RSA", enc);
} else if ("DSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "DSA", enc);
} else {
throw runtime.newNotImplementedError("public key algorithm: " + algorithm);
}
this.subject = newName(context, request.getSubject());
final Attribute[] attrs = request.getAttributes();
try {
// final RubyModule _ASN1 = _ASN1(runtime);
if (attrs != null) {
for (final Attribute attr : attrs) {
final ASN1ObjectIdentifier type = attr.getAttrType();
final ASN1Set values = attr.getAttrValues();
attributes.add(newAttribute(context, type, values));
}
}
} catch (IOException e) {
throw newRequestError(runtime, e);
}
return this;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class OCSPRequest method add_nonce.
@JRubyMethod(name = "add_nonce", rest = true)
public IRubyObject add_nonce(IRubyObject[] args) {
Ruby runtime = getRuntime();
if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0) {
nonce = generateNonce();
} else {
RubyString input = (RubyString) args[0];
nonce = input.getBytes();
}
addNonceImpl();
return this;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class OCSPRequest method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
return this;
RubyString derString = StringHelper.readPossibleDERInput(context, args[0]);
asn1bcReq = org.bouncycastle.asn1.ocsp.OCSPRequest.getInstance(derString.getBytes());
return this;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class OCSPResponse method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.getRuntime();
if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
return this;
RubyString derString = (RubyString) args[0];
try {
bcResp = org.bouncycastle.asn1.ocsp.OCSPResponse.getInstance(ASN1TaggedObject.fromByteArray(derString.getBytes()));
} catch (IOException e) {
throw newOCSPError(runtime, e);
}
return this;
}
use of org.jruby.RubyString in project jruby-openssl by jruby.
the class OCSPSingleResponse method initialize.
@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, IRubyObject derStr) {
Ruby runtime = context.getRuntime();
RubyString rubyDerStr = (RubyString) derStr;
try {
bcSingleResponse = SingleResponse.getInstance(DERTaggedObject.fromByteArray(rubyDerStr.getBytes()));
} catch (IOException e) {
throw newOCSPError(runtime, e);
}
return this;
}
Aggregations