001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org> 002// 003// SPDX-License-Identifier: Apache-2.0 004 005package org.pgpainless.util; 006 007import java.util.HashSet; 008import java.util.Set; 009 010/** 011 * Registry for known notations. 012 * Since signature verification must reject signatures with critical notations that are not known to the application, 013 * there must be some way to tell PGPainless which notations actually are known. 014 * 015 * To add a notation name, call {@link #addKnownNotation(String)}. 016 */ 017public class NotationRegistry { 018 019 private final Set<String> knownNotations = new HashSet<>(); 020 021 /** 022 * Add a known notation name into the registry. 023 * This will cause critical notations with that name to no longer invalidate the signature. 024 * 025 * @param notationName name of the notation 026 */ 027 public void addKnownNotation(String notationName) { 028 if (notationName == null) { 029 throw new NullPointerException("Notation name MUST NOT be null."); 030 } 031 knownNotations.add(notationName); 032 } 033 034 /** 035 * Return true if the notation name is registered in the registry. 036 * 037 * @param notationName name of the notation 038 * @return true if notation is known, false otherwise. 039 */ 040 public boolean isKnownNotation(String notationName) { 041 return knownNotations.contains(notationName); 042 } 043 044 /** 045 * Clear all known notations from the registry. 046 */ 047 public void clear() { 048 knownNotations.clear(); 049 } 050}