2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Fix byte array conversions

## Summary

Currently, KDE Connect for Android doesn't show the last 2 characters of the verification key when pairing a device. This MR solves this issue.

This bug is caused by incomplete conversions from byte arrays to strings in `SslHelper.java`:

```java
for (int i = 0; i < hash.length - 1; i++) {
    formatter.format("%02x", hash[i]);
}
```
The ```i < hash.length -1``` converts the bytes in the array up to (inclusive) the penultimate one. Removing the ```- 1``` allows for the last byte to be converted (this is the missing 2 characters).

BUG: 445955

## Test Plan

### Before:
Selecting a desktop from the available devices, then clicking the `Request Pairing` button causes a 62 character key to be displayed. It is 2 characters short of the actual key, which can be seen on the desktop KDE Connect app.

### After:
Selecting the `Request Pairing` button now shows the whole verification key, as intended.
This commit is contained in:
Ravi Mistry
2022-05-30 21:28:03 +00:00
committed by Nicolas Fella
parent 9834a690b4
commit 8f49ff57ab

View File

@@ -260,7 +260,7 @@ public class SslHelper {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(certificate.getEncoded());
Formatter formatter = new Formatter();
int i;
for (i = 0; i < hash.length - 1; i++) {
for (i = 0; i < hash.length; i++) {
formatter.format("%02x:", hash[i]);
}
formatter.format("%02x", hash[i]);
@@ -300,7 +300,7 @@ public class SslHelper {
byte[] hash = MessageDigest.getInstance("SHA-256").digest(concat);
Formatter formatter = new Formatter();
for (int i = 0; i < hash.length - 1; i++) {
for (int i = 0; i < hash.length; i++) {
formatter.format("%02x", hash[i]);
}
return formatter.toString();