Add more armor/dearmor tests

This commit is contained in:
Paul Schaub 2023-01-13 17:03:05 +01:00
parent 670aa0f242
commit 4726362df8
3 changed files with 189 additions and 8 deletions

View file

@ -4,8 +4,10 @@
package sop.external;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.fail;
public class JUtils {
@ -50,4 +52,21 @@ public class JUtils {
"Actual: <" + Arrays.toString(actual) + ">");
}
}
public static void assertAsciiArmorEquals(byte[] first, byte[] second) {
byte[] firstCleaned = removeArmorHeaders(first);
byte[] secondCleaned = removeArmorHeaders(second);
assertArrayEquals(firstCleaned, secondCleaned);
}
public static byte[] removeArmorHeaders(byte[] armor) {
String string = new String(armor, StandardCharsets.UTF_8);
string = string.replaceAll("Comment: .+\\R", "")
.replaceAll("Version: .+\\R", "")
.replaceAll("MessageID: .+\\R", "")
.replaceAll("Hash: .+\\R", "")
.replaceAll("Charset: .+\\R", "");
return string.getBytes(StandardCharsets.UTF_8);
}
}