• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org)
2 
3 package org.xbill.DNS;
4 
5 import java.io.*;
6 import org.xbill.DNS.utils.*;
7 
8 /**
9  * DLV - contains a Delegation Lookaside Validation record, which acts
10  * as the equivalent of a DS record in a lookaside zone.
11  * @see DNSSEC
12  * @see DSRecord
13  *
14  * @author David Blacka
15  * @author Brian Wellington
16  */
17 
18 public class DLVRecord extends Record {
19 
20 public static final int SHA1_DIGEST_ID = DSRecord.Digest.SHA1;
21 public static final int SHA256_DIGEST_ID = DSRecord.Digest.SHA1;
22 
23 private static final long serialVersionUID = 1960742375677534148L;
24 
25 private int footprint;
26 private int alg;
27 private int digestid;
28 private byte [] digest;
29 
DLVRecord()30 DLVRecord() {}
31 
32 Record
getObject()33 getObject() {
34 	return new DLVRecord();
35 }
36 
37 /**
38  * Creates a DLV Record from the given data
39  * @param footprint The original KEY record's footprint (keyid).
40  * @param alg The original key algorithm.
41  * @param digestid The digest id code.
42  * @param digest A hash of the original key.
43  */
44 public
DLVRecord(Name name, int dclass, long ttl, int footprint, int alg, int digestid, byte [] digest)45 DLVRecord(Name name, int dclass, long ttl, int footprint, int alg,
46 	  int digestid, byte [] digest)
47 {
48 	super(name, Type.DLV, dclass, ttl);
49 	this.footprint = checkU16("footprint", footprint);
50 	this.alg = checkU8("alg", alg);
51 	this.digestid = checkU8("digestid", digestid);
52 	this.digest = digest;
53 }
54 
55 void
rrFromWire(DNSInput in)56 rrFromWire(DNSInput in) throws IOException {
57 	footprint = in.readU16();
58 	alg = in.readU8();
59 	digestid = in.readU8();
60 	digest = in.readByteArray();
61 }
62 
63 void
rdataFromString(Tokenizer st, Name origin)64 rdataFromString(Tokenizer st, Name origin) throws IOException {
65 	footprint = st.getUInt16();
66 	alg = st.getUInt8();
67 	digestid = st.getUInt8();
68 	digest = st.getHex();
69 }
70 
71 /**
72  * Converts rdata to a String
73  */
74 String
rrToString()75 rrToString() {
76 	StringBuffer sb = new StringBuffer();
77 	sb.append(footprint);
78 	sb.append(" ");
79 	sb.append(alg);
80 	sb.append(" ");
81 	sb.append(digestid);
82 	if (digest != null) {
83 		sb.append(" ");
84 		sb.append(base16.toString(digest));
85 	}
86 
87 	return sb.toString();
88 }
89 
90 /**
91  * Returns the key's algorithm.
92  */
93 public int
getAlgorithm()94 getAlgorithm() {
95 	return alg;
96 }
97 
98 /**
99  *  Returns the key's Digest ID.
100  */
101 public int
getDigestID()102 getDigestID()
103 {
104 	return digestid;
105 }
106 
107 /**
108  * Returns the binary hash of the key.
109  */
110 public byte []
getDigest()111 getDigest() {
112 	return digest;
113 }
114 
115 /**
116  * Returns the key's footprint.
117  */
118 public int
getFootprint()119 getFootprint() {
120 	return footprint;
121 }
122 
123 void
rrToWire(DNSOutput out, Compression c, boolean canonical)124 rrToWire(DNSOutput out, Compression c, boolean canonical) {
125 	out.writeU16(footprint);
126 	out.writeU8(alg);
127 	out.writeU8(digestid);
128 	if (digest != null)
129 		out.writeByteArray(digest);
130 }
131 
132 }
133