home *** CD-ROM | disk | FTP | other *** search
- package org.xbill.DNS;
-
- import java.io.IOException;
- import org.xbill.DNS.utils.base64;
-
- abstract class KEYBase extends Record {
- protected int flags;
- protected int proto;
- protected int alg;
- protected byte[] key;
- protected int footprint = -1;
-
- protected KEYBase() {
- }
-
- public KEYBase(Name name, int type, int dclass, long ttl, int flags, int proto, int alg, byte[] key) {
- super(name, type, dclass, ttl);
- this.flags = Record.checkU16("flags", flags);
- this.proto = Record.checkU8("proto", proto);
- this.alg = Record.checkU8("alg", alg);
- this.key = key;
- }
-
- void rrFromWire(DNSInput in) throws IOException {
- this.flags = in.readU16();
- this.proto = in.readU8();
- this.alg = in.readU8();
- if (in.remaining() > 0) {
- this.key = in.readByteArray();
- }
-
- }
-
- String rrToString() {
- StringBuffer sb = new StringBuffer();
- sb.append(this.flags);
- sb.append(" ");
- sb.append(this.proto);
- sb.append(" ");
- sb.append(this.alg);
- if (this.key != null) {
- if (Options.check("multiline")) {
- sb.append(" (\n");
- sb.append(base64.formatString(this.key, 64, "\t", true));
- sb.append(" ; key_tag = ");
- sb.append(this.getFootprint());
- } else {
- sb.append(" ");
- sb.append(base64.toString(this.key));
- }
- }
-
- return sb.toString();
- }
-
- public int getFlags() {
- return this.flags;
- }
-
- public int getProtocol() {
- return this.proto;
- }
-
- public int getAlgorithm() {
- return this.alg;
- }
-
- public byte[] getKey() {
- return this.key;
- }
-
- public int getFootprint() {
- if (this.footprint >= 0) {
- return this.footprint;
- } else {
- int foot = 0;
- DNSOutput out = new DNSOutput();
- this.rrToWire(out, (Compression)null, false);
- byte[] rdata = out.toByteArray();
- if (this.alg == 1) {
- int d1 = rdata[rdata.length - 3] & 255;
- int d2 = rdata[rdata.length - 2] & 255;
- foot = (d1 << 8) + d2;
- } else {
- int i;
- for(i = 0; i < rdata.length - 1; i += 2) {
- int d1 = rdata[i] & 255;
- int d2 = rdata[i + 1] & 255;
- foot += (d1 << 8) + d2;
- }
-
- if (i < rdata.length) {
- int d1 = rdata[i] & 255;
- foot += d1 << 8;
- }
-
- foot += foot >> 16 & '\uffff';
- }
-
- this.footprint = foot & '\uffff';
- return this.footprint;
- }
- }
-
- void rrToWire(DNSOutput out, Compression c, boolean canonical) {
- out.writeU16(this.flags);
- out.writeU8(this.proto);
- out.writeU8(this.alg);
- if (this.key != null) {
- out.writeByteArray(this.key);
- }
-
- }
- }
-