diff --git a/ChangeLog.md b/ChangeLog.md index 8ef5496f..ddc53f68 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -3,6 +3,7 @@ * Tweak OSGi bundle manifest to allow Log4j 3. * [#362](https://github.com/mwiede/jsch/issues/362) fix PEM key parsing to work with windows line endings. * [#361](https://github.com/mwiede/jsch/issues/361) guard against `UIKeyboardInteractive` implementations that include NULL elements in the `String[]` returned from `promptKeyboardInteractive()`. + * Add a default implmentation of the deprecated `decrypt()` method to the `Identity` interface that throws an `UnsupportedOperationException`. * [0.2.9](https://github.com/mwiede/jsch/releases/tag/jsch-0.2.9) * [#293](https://github.com/mwiede/jsch/issues/293) allow UserAuthNone to be extended. * Make JGSS module optional. diff --git a/src/main/java/com/jcraft/jsch/AgentIdentity.java b/src/main/java/com/jcraft/jsch/AgentIdentity.java index 2fe5a2bc..3f83e4fb 100644 --- a/src/main/java/com/jcraft/jsch/AgentIdentity.java +++ b/src/main/java/com/jcraft/jsch/AgentIdentity.java @@ -60,12 +60,6 @@ public byte[] getSignature(byte[] data, String alg) { return agent.sign(blob, data, alg); } - @Override - @Deprecated - public boolean decrypt() { - throw new RuntimeException("not implemented"); - } - @Override public String getAlgName() { return algname; diff --git a/src/main/java/com/jcraft/jsch/Identity.java b/src/main/java/com/jcraft/jsch/Identity.java index 5aee38c8..f27c36bb 100644 --- a/src/main/java/com/jcraft/jsch/Identity.java +++ b/src/main/java/com/jcraft/jsch/Identity.java @@ -83,22 +83,30 @@ public default byte[] getSignature(byte[] data, String alg) { } /** + * This method is deprecated and the default implmentation of this method will throw an + * {@link UnsupportedOperationException}. + * * @deprecated The decryption should be done automatically in {@link #setPassphrase(byte[])} + * @return true if the decryption is succeeded or this identity is not cyphered. * @see #setPassphrase(byte[]) */ @Deprecated - public boolean decrypt(); + public default boolean decrypt() { + throw new UnsupportedOperationException("not implemented"); + } /** * Returns the name of the key algorithm. * - * @return "ssh-rsa" or "ssh-dss" + * @return the name of the key algorithm */ public String getAlgName(); /** * Returns the name of this identity. It will be useful to identify this object in the * {@link IdentityRepository}. + * + * @return the name of this identity */ public String getName(); diff --git a/src/main/java/com/jcraft/jsch/IdentityFile.java b/src/main/java/com/jcraft/jsch/IdentityFile.java index 89555674..af55a0b4 100644 --- a/src/main/java/com/jcraft/jsch/IdentityFile.java +++ b/src/main/java/com/jcraft/jsch/IdentityFile.java @@ -45,7 +45,7 @@ static IdentityFile newInstance(String name, byte[] prvkey, byte[] pubkey, return new IdentityFile(name, kpair); } - private IdentityFile(String name, KeyPair kpair) throws JSchException { + private IdentityFile(String name, KeyPair kpair) { this.identity = name; this.kpair = kpair; } @@ -94,30 +94,21 @@ public byte[] getSignature(byte[] data, String alg) { return kpair.getSignature(data, alg); } - /** - * @deprecated This method should not be invoked. - * @see #setPassphrase(byte[] passphrase) - */ - @Override - @Deprecated - public boolean decrypt() { - throw new RuntimeException("not implemented"); - } - /** * Returns the name of the key algorithm. * - * @return "ssh-rsa" or "ssh-dss" + * @return the name of the key algorithm */ @Override public String getAlgName() { - byte[] name = kpair.getKeyTypeName(); - return Util.byte2str(name); + return kpair.getKeyTypeString(); } /** * Returns the name of this identity. It will be useful to identify this object in the * {@link IdentityRepository}. + * + * @return the name of this identity */ @Override public String getName() {