Skip to content

Commit

Permalink
Add a default implmentation of the deprecated decrypt() method to t…
Browse files Browse the repository at this point in the history
…he `Identity` interface that throws an `UnsupportedOperationException`.
  • Loading branch information
norrisjeremy committed Jul 22, 2023
1 parent 432eebe commit a240218
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 22 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/jcraft/jsch/AgentIdentity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/jcraft/jsch/Identity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>true</code> 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();

Expand Down
19 changes: 5 additions & 14 deletions src/main/java/com/jcraft/jsch/IdentityFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a240218

Please sign in to comment.