2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-09-07 13:35:58 +02:00
|
|
|
package org.pgpainless.policy;
|
2021-02-19 21:22:25 +01:00
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registry for known notations.
|
|
|
|
* Since signature verification must reject signatures with critical notations that are not known to the application,
|
|
|
|
* there must be some way to tell PGPainless which notations actually are known.
|
|
|
|
*
|
|
|
|
* To add a notation name, call {@link #addKnownNotation(String)}.
|
|
|
|
*/
|
2021-04-26 13:38:12 +02:00
|
|
|
public class NotationRegistry {
|
2021-02-19 21:22:25 +01:00
|
|
|
|
|
|
|
private final Set<String> knownNotations = new HashSet<>();
|
|
|
|
|
2021-02-25 19:57:18 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-02-19 21:22:25 +01:00
|
|
|
public void addKnownNotation(String notationName) {
|
|
|
|
if (notationName == null) {
|
|
|
|
throw new NullPointerException("Notation name MUST NOT be null.");
|
|
|
|
}
|
|
|
|
knownNotations.add(notationName);
|
|
|
|
}
|
|
|
|
|
2021-02-25 19:57:18 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-02-19 21:22:25 +01:00
|
|
|
public boolean isKnownNotation(String notationName) {
|
|
|
|
return knownNotations.contains(notationName);
|
|
|
|
}
|
2021-02-25 19:57:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all known notations from the registry.
|
|
|
|
*/
|
|
|
|
public void clear() {
|
|
|
|
knownNotations.clear();
|
|
|
|
}
|
2021-02-19 21:22:25 +01:00
|
|
|
}
|