Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RespID.java « ocsp « cert « spongycastle « org « java « main « src « pkix - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7510200d5b7a07104d0f5d4a100e147fb59ee02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.spongycastle.cert.ocsp;

import java.io.OutputStream;

import org.spongycastle.asn1.DERNull;
import org.spongycastle.asn1.DEROctetString;
import org.spongycastle.asn1.ocsp.ResponderID;
import org.spongycastle.asn1.oiw.OIWObjectIdentifiers;
import org.spongycastle.asn1.x500.X500Name;
import org.spongycastle.asn1.x509.AlgorithmIdentifier;
import org.spongycastle.asn1.x509.SubjectPublicKeyInfo;
import org.spongycastle.operator.DigestCalculator;

/**
 * Carrier for a ResponderID.
 */
public class RespID
{
    public static final AlgorithmIdentifier HASH_SHA1 = new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1, DERNull.INSTANCE);

    ResponderID id;

    public RespID(
        ResponderID id)
    {
        this.id = id;
    }

    public RespID(
        X500Name name)
    {
        this.id = new ResponderID(name);
    }

    /**
     * Calculate a RespID based on the public key of the responder.
     *
     * @param subjectPublicKeyInfo the info structure for the responder public key.
     * @param digCalc a SHA-1 digest calculator.
     * @throws OCSPException on exception creating ID.
     */
    public RespID(
        SubjectPublicKeyInfo     subjectPublicKeyInfo,
        DigestCalculator         digCalc)
        throws OCSPException
    {
        try
        {
            if (!digCalc.getAlgorithmIdentifier().equals(HASH_SHA1))
            {
                throw new IllegalArgumentException("only SHA-1 can be used with RespID");
            }

            OutputStream     digOut = digCalc.getOutputStream();

            digOut.write(subjectPublicKeyInfo.getPublicKeyData().getBytes());
            digOut.close();

            this.id = new ResponderID(new DEROctetString(digCalc.getDigest()));
        }
        catch (Exception e)
        {
            throw new OCSPException("problem creating ID: " + e, e);
        }
    }

    public ResponderID toASN1Object()
    {
        return id;
    }

    public boolean equals(
        Object  o)
    {
        if (!(o instanceof RespID))
        {
            return false;
        }

        RespID obj = (RespID)o;

        return id.equals(obj.id);
    }

    public int hashCode()
    {
        return id.hashCode();
    }
}