~ubuntu-branches/ubuntu/wily/dnsjava/wily-proposed

« back to all changes in this revision

Viewing changes to org/xbill/DNS/SSHFPRecord.java

  • Committer: Bazaar Package Importer
  • Author(s): Thierry Carrez
  • Date: 2009-07-21 15:17:03 UTC
  • Revision ID: james.westby@ubuntu.com-20090721151703-6v0107p1s3h7gv1c
Tags: upstream-2.0.6
ImportĀ upstreamĀ versionĀ 2.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 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
 * SSH Fingerprint - stores the fingerprint of an SSH host key.
 
10
 *
 
11
 * @author Brian Wellington
 
12
 */
 
13
 
 
14
public class SSHFPRecord extends Record {
 
15
 
 
16
public static class Algorithm {
 
17
        private Algorithm() {}
 
18
 
 
19
        public static final int RSA = 1;
 
20
        public static final int DSS = 2;
 
21
}
 
22
 
 
23
public static class Digest {
 
24
        private Digest() {}
 
25
 
 
26
        public static final int SHA1 = 1;
 
27
}
 
28
 
 
29
private int alg;
 
30
private int digestType;
 
31
private byte [] fingerprint;
 
32
 
 
33
SSHFPRecord() {} 
 
34
 
 
35
Record
 
36
getObject() {
 
37
        return new SSHFPRecord();
 
38
}
 
39
 
 
40
/**
 
41
 * Creates an SSHFP Record from the given data.
 
42
 * @param alg The public key's algorithm.
 
43
 * @param digestType The public key's digest type.
 
44
 * @param fingerprint The public key's fingerprint.
 
45
 */
 
46
public
 
47
SSHFPRecord(Name name, int dclass, long ttl, int alg, int digestType,
 
48
            byte [] fingerprint)
 
49
{
 
50
        super(name, Type.SSHFP, dclass, ttl);
 
51
        this.alg = checkU8("alg", alg);
 
52
        this.digestType = checkU8("digestType", digestType);
 
53
        this.fingerprint = fingerprint;
 
54
}
 
55
 
 
56
void
 
57
rrFromWire(DNSInput in) throws IOException {
 
58
        alg = in.readU8();
 
59
        digestType = in.readU8();
 
60
        fingerprint = in.readByteArray();
 
61
}
 
62
 
 
63
void
 
64
rdataFromString(Tokenizer st, Name origin) throws IOException {
 
65
        alg = st.getUInt8();
 
66
        digestType = st.getUInt8();
 
67
        fingerprint = st.getHex(true);
 
68
}
 
69
 
 
70
String
 
71
rrToString() {
 
72
        StringBuffer sb = new StringBuffer();
 
73
        sb.append(alg);
 
74
        sb.append(" ");
 
75
        sb.append(digestType);
 
76
        sb.append(" ");
 
77
        sb.append(base16.toString(fingerprint));
 
78
        return sb.toString();
 
79
}
 
80
 
 
81
/** Returns the public key's algorithm. */
 
82
public int
 
83
getAlgorithm() {
 
84
        return alg;
 
85
}
 
86
 
 
87
/** Returns the public key's digest type. */
 
88
public int
 
89
getDigestType() {
 
90
        return digestType;
 
91
}
 
92
 
 
93
/** Returns the fingerprint */
 
94
public byte []
 
95
getFingerPrint() {
 
96
        return fingerprint;
 
97
}
 
98
 
 
99
void
 
100
rrToWire(DNSOutput out, Compression c, boolean canonical) {
 
101
        out.writeU8(alg);
 
102
        out.writeU8(digestType);
 
103
        out.writeByteArray(fingerprint);
 
104
}
 
105
 
 
106
}