~brian-thomason/+junk/bouncycastle

« back to all changes in this revision

Viewing changes to src/org/bouncycastle/ocsp/RespID.java

  • Committer: Brian Thomason
  • Date: 2011-12-20 17:20:32 UTC
  • Revision ID: brian.thomason@canonical.com-20111220172032-rdtm13jgdxtksacr
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.bouncycastle.ocsp;
 
2
 
 
3
import java.security.MessageDigest;
 
4
import java.security.PublicKey;
 
5
 
 
6
import javax.security.auth.x500.X500Principal;
 
7
 
 
8
import org.bouncycastle.asn1.ASN1InputStream;
 
9
import org.bouncycastle.asn1.ASN1OctetString;
 
10
import org.bouncycastle.asn1.DEROctetString;
 
11
import org.bouncycastle.asn1.ocsp.ResponderID;
 
12
import org.bouncycastle.asn1.x500.X500Name;
 
13
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
 
14
 
 
15
/**
 
16
 * Carrier for a ResponderID.
 
17
 */
 
18
public class RespID
 
19
{
 
20
    ResponderID id;
 
21
 
 
22
    public RespID(
 
23
        ResponderID id)
 
24
    {
 
25
        this.id = id;
 
26
    }
 
27
 
 
28
    public RespID(
 
29
        X500Principal   name)
 
30
    {
 
31
        this.id = new ResponderID(X500Name.getInstance(name.getEncoded()));
 
32
    }
 
33
 
 
34
    public RespID(
 
35
        PublicKey   key)
 
36
        throws OCSPException
 
37
    {
 
38
        try
 
39
        {
 
40
            // TODO Allow specification of a particular provider
 
41
            MessageDigest digest = OCSPUtil.createDigestInstance("SHA1", null);
 
42
 
 
43
            ASN1InputStream aIn = new ASN1InputStream(key.getEncoded());
 
44
            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());
 
45
 
 
46
            digest.update(info.getPublicKeyData().getBytes());
 
47
 
 
48
            ASN1OctetString keyHash = new DEROctetString(digest.digest());
 
49
 
 
50
            this.id = new ResponderID(keyHash);
 
51
        }
 
52
        catch (Exception e)
 
53
        {
 
54
            throw new OCSPException("problem creating ID: " + e, e);
 
55
        }
 
56
    }
 
57
 
 
58
    public ResponderID toASN1Object()
 
59
    {
 
60
        return id;
 
61
    }
 
62
 
 
63
    public boolean equals(
 
64
        Object  o)
 
65
    {
 
66
        if (!(o instanceof RespID))
 
67
        {
 
68
            return false;
 
69
        }
 
70
 
 
71
        RespID   obj = (RespID)o;
 
72
 
 
73
        return id.equals(obj.id);
 
74
    }
 
75
 
 
76
    public int hashCode()
 
77
    {
 
78
        return id.hashCode();
 
79
    }
 
80
}