2 * Copyright (c) 2005 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
39 private SecurityStatus mSecurityStatus;
41 /** Create a new, blank SRRset. */
45 mSecurityStatus = new SecurityStatus();
49 * Create a new SRRset from an existing RRset. This SRRset will contain that
50 * same internal Record objects as the original RRset.
52 @SuppressWarnings("unchecked") // org.xbill.DNS.RRset isn't typesafe-aware.
53 public SRRset(RRset r)
57 for (Iterator i = r.rrs(); i.hasNext();)
59 addRR((Record) i.next());
62 for (Iterator i = r.sigs(); i.hasNext();)
64 addRR((Record) i.next());
69 * Clone this SRRset, giving the copy a new TTL. The copy is independent
70 * from the original except for the security status.
72 * @param withNewTTL The new TTL to apply to the RRset. This applies to
73 * contained RRsig records as well.
74 * @return The cloned SRRset.
76 // public SRRset cloneSRRset(long withNewTTL)
78 // SRRset nr = new SRRset();
80 // for (Iterator i = rrs(); i.hasNext();)
82 // nr.addRR(((Record) i.next()).withTTL(withNewTTL));
84 // for (Iterator i = sigs(); i.hasNext();)
86 // nr.addRR(((Record) i.next()).withTTL(withNewTTL));
89 // nr.mSecurityStatus = mSecurityStatus;
94 public SRRset cloneSRRsetNoSigs()
96 SRRset nr = new SRRset();
97 for (Iterator i = rrs(); i.hasNext();)
99 // NOTE: should this clone the records as well?
100 nr.addRR((Record) i.next());
102 // Do not copy the SecurityStatus reference
109 * Return the current security status (generally: UNCHECKED, BOGUS, or
112 public int getSecurity()
114 return getSecurityStatus();
118 * Return the current security status (generally: UNCHECKED, BOGUS, or
121 public int getSecurityStatus()
123 return mSecurityStatus.getStatus();
127 * Set the current security status for this SRRset. This status will be
128 * shared amongst all copies of this SRRset (created with cloneSRRset())
130 public void setSecurityStatus(byte status)
132 mSecurityStatus.setStatus(status);
135 public int totalSize() {
137 for (Iterator i = sigs(); i.hasNext(); ) {
140 return size() + num_sigs;
144 * @return The total number of records (data + sigs) in the SRRset.
146 public int getNumRecords()
151 public RRSIGRecord firstSig() {
152 for (Iterator i = sigs(); i.hasNext(); ) {
153 return (RRSIGRecord) i.next();
158 * @return true if this RRset has RRSIG records that cover data records.
159 * (i.e., RRSIG SRRsets return false)
161 public boolean isSigned()
163 if (getType() == Type.RRSIG) return false;
164 return firstSig() != null;
168 * @return The "signer" name for this SRRset, if signed, or null if not.
170 public Name getSignerName()
172 RRSIGRecord sig = (RRSIGRecord) firstSig();
173 if (sig == null) return null;
174 return sig.getSigner();
177 // public void setTTL(long ttl)
181 // throw new IllegalArgumentException("ttl can't be less than zero, stupid! was " + ttl);
183 // super.setTTL(ttl);