SignatureVerifierPluginTest

This commit is contained in:
Milos Kozak 2019-10-28 13:45:42 +01:00
parent c10963dcbd
commit 0da6377687
2 changed files with 18 additions and 2 deletions

View file

@ -160,11 +160,12 @@ public class SignatureVerifierPlugin extends PluginBase implements ConstraintsIn
return sb.toString(); return sb.toString();
} }
private String singleCharUnMap(String shortHash) { public String singleCharUnMap(String shortHash) {
byte[] array = new byte[shortHash.length()]; byte[] array = new byte[shortHash.length()];
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < array.length; i++) { for (int i = 0; i < array.length; i++) {
sb.append(String.format("%02x",(int) map.charAt(map.indexOf(shortHash.charAt(i))))); if (i != 0) sb.append(":");
sb.append(String.format("%02X", 0xFF & map.charAt(map.indexOf(shortHash.charAt(i)))));
} }
return sb.toString(); return sb.toString();
} }

View file

@ -0,0 +1,15 @@
package info.nightscout.androidaps.plugins.constraints.signatureVerifier
import org.junit.Test
import org.junit.Assert.*
class SignatureVerifierPluginTest {
@Test
fun singleCharUnMapTest() {
val key = "2ΙšÄΠΒϨÒÇeЄtЄЗž-*Ж*ZcHijЊÄœ<|x\"Ε"
val unmapped = SignatureVerifierPlugin.getPlugin().singleCharUnMap(key)
assertEquals("32:99:61:C4:A0:92:E8:D2:C7:65:04:74:04:17:7E:2D:2A:16:2A:5A:63:48:69:6A:0A:C4:53:3C:7C:78:22:95", unmapped)
}
}