-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compat] implement PKey::DSA public_to_der and public_to_pem
- Loading branch information
Showing
2 changed files
with
65 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ | |
import static org.jruby.ext.openssl.impl.PKey.readDSAPublicKey; | ||
import static org.jruby.ext.openssl.impl.PKey.toASN1Primitive; | ||
import static org.jruby.ext.openssl.impl.PKey.toDerDSAKey; | ||
import static org.jruby.ext.openssl.impl.PKey.toDerDSAPublicKey; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Ola Bini</a> | ||
|
@@ -298,6 +299,21 @@ public RubyBoolean private_p() { | |
return privateKey != null ? getRuntime().getTrue() : getRuntime().getFalse(); | ||
} | ||
|
||
@JRubyMethod(name = "public_to_der") | ||
public RubyString public_to_der(ThreadContext context) { | ||
final byte[] bytes; | ||
try { | ||
bytes = toDerDSAPublicKey(publicKey); | ||
} | ||
catch (NoClassDefFoundError e) { | ||
throw newDSAError(getRuntime(), bcExceptionMessage(e)); | ||
} | ||
catch (IOException e) { | ||
throw newDSAError(getRuntime(), e.getMessage(), e); | ||
} | ||
return StringHelper.newString(context.runtime, bytes); | ||
} | ||
|
||
@Override | ||
@JRubyMethod(name = "to_der") | ||
public RubyString to_der() { | ||
|
@@ -398,6 +414,21 @@ public RubyString to_pem(final ThreadContext context, final IRubyObject[] args) | |
} | ||
} | ||
|
||
@JRubyMethod | ||
public RubyString public_to_pem(ThreadContext context) { | ||
try { | ||
final StringWriter writer = new StringWriter(); | ||
PEMInputOutput.writeDSAPublicKey(writer, publicKey); | ||
return RubyString.newString(context.runtime, writer.getBuffer()); | ||
} | ||
catch (NoClassDefFoundError ncdfe) { | ||
throw newDSAError(context.runtime, bcExceptionMessage(ncdfe)); | ||
} | ||
catch (IOException e) { | ||
throw newDSAError(context.runtime, e.getMessage(), e); | ||
} | ||
} | ||
|
||
@JRubyMethod // ossl_dsa_sign | ||
public IRubyObject syssign(IRubyObject data) { | ||
final Ruby runtime = getRuntime(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters