From 0c7165b5bcbf6914802d465ffa8b7fde5ca61d5d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 May 2024 12:50:35 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20Freenet-specific?= =?utf8?q?=20Base64=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/fcp/FreenetBase64Test.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java diff --git a/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java b/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java new file mode 100644 index 0000000..4033aed --- /dev/null +++ b/src/test/java/net/pterodactylus/fcp/FreenetBase64Test.java @@ -0,0 +1,45 @@ +package net.pterodactylus.fcp; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +import java.util.List; + +import org.junit.Test; + +/** + * Unit test for {@link FreenetBase64Test}. + */ +public class FreenetBase64Test { + + @Test + public void testEncodingVectorsFromRfc4648() { + getRfc4648TestVectors().forEach(vector -> assertThat(encoder.encode(vector[0].getBytes(UTF_8)), equalTo(vector[1]))); + } + + @Test + public void testDecodingVectorsFromRfc4648() { + getRfc4648TestVectors().forEach(vector -> assertThat(encoder.decode(vector[1]), equalTo(vector[0].getBytes(UTF_8)))); + } + + private static List getRfc4648TestVectors() { + return asList( + vector("", ""), + vector("f", "Zg=="), + vector("fo", "Zm8="), + vector("foo", "Zm9v"), + vector("foob", "Zm9vYg=="), + vector("fooba", "Zm9vYmE="), + vector("foobar", "Zm9vYmFy") + ); + } + + private static String[] vector(String plain, String encoded) { + return new String[] { plain, encoded }; + } + + private final FreenetBase64 encoder = new FreenetBase64(); + +} -- 2.7.4