Avoid UnsupportedEncodingException & use const from StandardCharsets (#11948)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp
2022-01-03 16:05:08 +01:00
committed by GitHub
parent 3f54327d5a
commit 167f8ebc49
52 changed files with 180 additions and 414 deletions

View File

@@ -15,11 +15,11 @@ package org.openhab.binding.myq.internal.handler;
import static org.openhab.binding.myq.internal.MyQBindingConstants.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -485,7 +485,7 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR
ContentResponse response = request.send();
logger.debug("Login Code {} Response {}", response.getStatus(), response.getContentAsString());
return response;
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
} catch (NoSuchAlgorithmException e) {
throw new ExecutionException(e.getCause());
}
}
@@ -613,16 +613,15 @@ public class MyQAccountHandler extends BaseBridgeHandler implements AccessTokenR
return sb.toString();
}
private String generateCodeVerifier() throws UnsupportedEncodingException {
private String generateCodeVerifier() {
SecureRandom secureRandom = new SecureRandom();
byte[] codeVerifier = new byte[32];
secureRandom.nextBytes(codeVerifier);
return Base64.getUrlEncoder().withoutPadding().encodeToString(codeVerifier);
}
private String generateCodeChallange(String codeVerifier)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
byte[] bytes = codeVerifier.getBytes("US-ASCII");
private String generateCodeChallange(String codeVerifier) throws NoSuchAlgorithmException {
byte[] bytes = codeVerifier.getBytes(StandardCharsets.US_ASCII);
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(bytes, 0, bytes.length);
byte[] digest = messageDigest.digest();