001: // Copyright (c) 2002-2004 Brian Wellington (bwelling@xbill.org)
002:
003: package org.xbill.DNS;
004:
005: import java.io.*;
006: import org.xbill.DNS.utils.*;
007:
008: /**
009: * DS - contains a Delegation Signer record, which acts as a
010: * placeholder for KEY records in the parent zone.
011: * @see DNSSEC
012: *
013: * @author David Blacka
014: * @author Brian Wellington
015: */
016:
017: public class DSRecord extends Record {
018:
019: public static final byte SHA1_DIGEST_ID = 1;
020:
021: private int footprint;
022: private int alg;
023: private int digestid;
024: private byte[] digest;
025:
026: DSRecord() {
027: }
028:
029: Record getObject() {
030: return new DSRecord();
031: }
032:
033: /**
034: * Creates a DS Record from the given data
035: * @param footprint The original KEY record's footprint (keyid).
036: * @param alg The original key algorithm.
037: * @param digestid The digest id code.
038: * @param digest A hash of the original key.
039: */
040: public DSRecord(Name name, int dclass, long ttl, int footprint,
041: int alg, int digestid, byte[] digest) {
042: super (name, Type.DS, dclass, ttl);
043: this .footprint = checkU16("footprint", footprint);
044: this .alg = checkU8("alg", alg);
045: this .digestid = checkU8("digestid", digestid);
046: this .digest = digest;
047: }
048:
049: void rrFromWire(DNSInput in) throws IOException {
050: footprint = in.readU16();
051: alg = in.readU8();
052: digestid = in.readU8();
053: digest = in.readByteArray();
054: }
055:
056: void rdataFromString(Tokenizer st, Name origin) throws IOException {
057: footprint = st.getUInt16();
058: alg = st.getUInt8();
059: digestid = st.getUInt8();
060: digest = st.getHex();
061: }
062:
063: /**
064: * Converts rdata to a String
065: */
066: String rrToString() {
067: StringBuffer sb = new StringBuffer();
068: sb.append(footprint);
069: sb.append(" ");
070: sb.append(alg);
071: sb.append(" ");
072: sb.append(digestid);
073: if (digest != null) {
074: sb.append(" ");
075: sb.append(base16.toString(digest));
076: }
077:
078: return sb.toString();
079: }
080:
081: /**
082: * Returns the key's algorithm.
083: */
084: public int getAlgorithm() {
085: return alg;
086: }
087:
088: /**
089: * Returns the key's Digest ID.
090: */
091: public int getDigestID() {
092: return digestid;
093: }
094:
095: /**
096: * Returns the binary hash of the key.
097: */
098: public byte[] getDigest() {
099: return digest;
100: }
101:
102: /**
103: * Returns the key's footprint.
104: */
105: public int getFootprint() {
106: return footprint;
107: }
108:
109: void rrToWire(DNSOutput out, Compression c, boolean canonical) {
110: out.writeU16(footprint);
111: out.writeU8(alg);
112: out.writeU8(digestid);
113: if (digest != null)
114: out.writeByteArray(digest);
115: }
116:
117: }
|