mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-09 10:19:47 +02:00
Add more armor/dearmor tests
This commit is contained in:
parent
670aa0f242
commit
4726362df8
3 changed files with 189 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue