2 * Copyright (c) 2009 VeriSign. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer. 2. Redistributions in
9 * binary form must reproduce the above copyright notice, this list of
10 * conditions and the following disclaimer in the documentation and/or other
11 * materials provided with the distribution. 3. The name of the author may not
12 * be used to endorse or promote products derived from this software without
13 * specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
20 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 package com.versign.tat.dnssec;
32 import org.xbill.DNS.*;
35 * A version of the RRset class overrides the standard security status.
37 public class SRRset extends RRset {
38 private SecurityStatus mSecurityStatus;
40 /** Create a new, blank SRRset. */
43 mSecurityStatus = new SecurityStatus();
48 * Create a new SRRset from an existing RRset. This SRRset will contain that
49 * same internal Record objects as the original RRset.
51 @SuppressWarnings("unchecked")
52 // org.xbill.DNS.RRset isn't typesafe-aware.
53 public SRRset(RRset r) {
56 for (Iterator i = r.rrs(); i.hasNext();) {
57 addRR((Record) i.next());
60 for (Iterator i = r.sigs(); i.hasNext();) {
61 addRR((Record) i.next());
66 * Return the current security status (generally: UNCHECKED, BOGUS, or
69 public int getSecurity() {
70 return getSecurityStatus();
74 * Return the current security status (generally: UNCHECKED, BOGUS, or
77 public byte getSecurityStatus() {
78 return mSecurityStatus.getStatus();
82 * Set the current security status for this SRRset. This status will be
83 * shared amongst all copies of this SRRset (created with cloneSRRset())
85 public void setSecurityStatus(byte status) {
86 mSecurityStatus.setStatus(status);
89 public Iterator<Record> rrs() {
90 return (Iterator<Record>) rrs();
93 public Iterator<RRSIGRecord> sigs() {
94 return (Iterator<RRSIGRecord>) sigs();
97 public int totalSize() {
99 for (Iterator<RRSIGRecord> i = sigs(); i.hasNext();) {
102 return size() + num_sigs;
106 * @return The total number of records (data + sigs) in the SRRset.
108 public int getNumRecords() {
112 public RRSIGRecord firstSig() {
113 for (Iterator<RRSIGRecord> i = sigs(); i.hasNext();) {
120 * @return true if this RRset has RRSIG records that cover data records.
121 * (i.e., RRSIG SRRsets return false)
123 public boolean isSigned() {
124 if (getType() == Type.RRSIG) return false;
125 return firstSig() != null;
129 * @return The "signer" name for this SRRset, if signed, or null if not.
131 public Name getSignerName() {
132 RRSIGRecord sig = (RRSIGRecord) firstSig();
133 if (sig == null) return null;
134 return sig.getSigner();