aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/spongycastle/core/src/main/jdk1.1/java/security/cert/Certificate.java
blob: 201e209a38df483f672f240a0806d1218aa09476 (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
package java.security.cert;

import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.SignatureException;

public abstract class Certificate extends Object
{
    private String type;

    protected Certificate(String type)
    {
        this.type = type;
    }

    public boolean equals(Object other)
    {
        if ( !(other instanceof Certificate) )
            return false;

        if ( other == this )
            return true;

        try
        {
            byte[] enc1 = getEncoded();
            byte[] enc2 = ((Certificate)other).getEncoded();

            return MessageDigest.isEqual(enc1, enc2);
        }
        catch (CertificateEncodingException e)
        {
            return false;
        }
    }

    public final String getType()
    {
        return type;
    }

    // XXX
    public int hashCode()
    {
        try
        {
            byte[] enc1 = getEncoded();
            int hc = 0;
            for (int i = 0; i < enc1.length; i++)
            {
                hc += enc1[i];
            }

            return hc;
        }
        catch (CertificateEncodingException e)
        {
            return 0;
        }
    }

    public abstract byte[] getEncoded()
        throws CertificateEncodingException;

    public abstract PublicKey getPublicKey();

    public abstract String toString();

    public abstract void verify(PublicKey key)
        throws CertificateException, NoSuchAlgorithmException,
        InvalidKeyException, NoSuchProviderException, SignatureException;

    public abstract void verify(PublicKey key, String sigProvider)
        throws CertificateException, NoSuchAlgorithmException,
        InvalidKeyException, NoSuchProviderException, SignatureException;
}