001/* 002 * Copyright 2015-2024 the original author or authors 003 * 004 * This software is licensed under the Apache License, Version 2.0, 005 * the GNU Lesser General Public License version 2 or later ("LGPL") 006 * and the WTFPL. 007 * You may choose either license to govern your use of this software only 008 * upon the condition that you accept all of the terms of either 009 * the Apache License 2.0, the LGPL 2.1+ or the WTFPL. 010 */ 011package org.minidns.dnssec; 012 013import java.util.Collections; 014import java.util.Set; 015 016import org.minidns.MiniDnsException; 017 018public final class DnssecResultNotAuthenticException extends MiniDnsException { 019 020 /** 021 * 022 */ 023 private static final long serialVersionUID = 1L; 024 025 private final Set<DnssecUnverifiedReason> unverifiedReasons; 026 027 private DnssecResultNotAuthenticException(String message, Set<DnssecUnverifiedReason> unverifiedReasons) { 028 super(message); 029 if (unverifiedReasons.isEmpty()) { 030 throw new IllegalArgumentException(); 031 } 032 this.unverifiedReasons = Collections.unmodifiableSet(unverifiedReasons); 033 } 034 035 public static DnssecResultNotAuthenticException from(Set<DnssecUnverifiedReason> unverifiedReasons) { 036 StringBuilder sb = new StringBuilder(); 037 sb.append("DNSSEC result not authentic. Reasons: "); 038 for (DnssecUnverifiedReason reason : unverifiedReasons) { 039 sb.append(reason).append('.'); 040 } 041 042 return new DnssecResultNotAuthenticException(sb.toString(), unverifiedReasons); 043 } 044 045 public Set<DnssecUnverifiedReason> getUnverifiedReasons() { 046 return unverifiedReasons; 047 } 048}