From 577ee143b5cd5c55eee534bc0bc6c5dc9b48eb36 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Thu, 25 Feb 2021 19:57:18 +0100 Subject: [PATCH] Add NotationRegistryTest --- .../org/pgpainless/util/NotationRegistry.java | 19 ++++++++ .../pgpainless/util/NotationRegistryTest.java | 46 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 pgpainless-core/src/test/java/org/pgpainless/util/NotationRegistryTest.java diff --git a/pgpainless-core/src/main/java/org/pgpainless/util/NotationRegistry.java b/pgpainless-core/src/main/java/org/pgpainless/util/NotationRegistry.java index 3366fc0a..ebd0859f 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/util/NotationRegistry.java +++ b/pgpainless-core/src/main/java/org/pgpainless/util/NotationRegistry.java @@ -41,6 +41,12 @@ public final class NotationRegistry { return INSTANCE; } + /** + * Add a known notation name into the registry. + * This will cause critical notations with that name to no longer invalidate the signature. + * + * @param notationName name of the notation + */ public void addKnownNotation(String notationName) { if (notationName == null) { throw new NullPointerException("Notation name MUST NOT be null."); @@ -48,7 +54,20 @@ public final class NotationRegistry { knownNotations.add(notationName); } + /** + * Return true if the notation name is registered in the registry. + * + * @param notationName name of the notation + * @return true if notation is known, false otherwise. + */ public boolean isKnownNotation(String notationName) { return knownNotations.contains(notationName); } + + /** + * Clear all known notations from the registry. + */ + public void clear() { + knownNotations.clear(); + } } diff --git a/pgpainless-core/src/test/java/org/pgpainless/util/NotationRegistryTest.java b/pgpainless-core/src/test/java/org/pgpainless/util/NotationRegistryTest.java new file mode 100644 index 00000000..710b1bce --- /dev/null +++ b/pgpainless-core/src/test/java/org/pgpainless/util/NotationRegistryTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2021 Paul Schaub. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.pgpainless.util; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class NotationRegistryTest { + + @BeforeEach + public void setup() { + NotationRegistry.getInstance().clear(); + } + + @Test + public void notationIsKnownOnceAddedAndUnknownOnceCleared() { + NotationRegistry registry = NotationRegistry.getInstance(); + + assertFalse(registry.isKnownNotation("proof@metacode.biz"), "Notation is initially not known."); + assertFalse(registry.isKnownNotation("unkown@notation.data")); + + registry.addKnownNotation("proof@metacode.biz"); + assertTrue(registry.isKnownNotation("proof@metacode.biz"), "Notation is known after it has been added to the registry."); + assertFalse(registry.isKnownNotation("unknown@notation.data")); + + registry.clear(); + assertFalse(registry.isKnownNotation("proof@metacode.biz"), "Notation is no longer known after registry is cleared."); + assertFalse(registry.isKnownNotation("unknown@notation.data")); + } +}