1package org.bouncycastle.x509.extension;
2
3import java.io.IOException;
4import java.security.InvalidKeyException;
5import java.security.PublicKey;
6
7import org.bouncycastle.asn1.ASN1OctetString;
8import org.bouncycastle.asn1.x509.SubjectKeyIdentifier;
9import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
10
11/**
12 * A high level subject key identifier.
13 * @deprecated use JcaX509ExtensionUtils andSubjectKeyIdentifier.getInstance()
14 */
15public class SubjectKeyIdentifierStructure
16    extends SubjectKeyIdentifier
17{
18    /**
19     * Constructor which will take the byte[] returned from getExtensionValue()
20     *
21     * @param encodedValue a DER octet encoded string with the extension structure in it.
22     * @throws IOException on parsing errors.
23     */
24    public SubjectKeyIdentifierStructure(
25        byte[]  encodedValue)
26        throws IOException
27    {
28        super((ASN1OctetString)X509ExtensionUtil.fromExtensionValue(encodedValue));
29    }
30
31    private static ASN1OctetString fromPublicKey(
32        PublicKey pubKey)
33        throws InvalidKeyException
34    {
35        try
36        {
37            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(pubKey.getEncoded());
38
39            return (ASN1OctetString)(new SubjectKeyIdentifier(info).toASN1Object());
40        }
41        catch (Exception e)
42        {
43            throw new InvalidKeyException("Exception extracting key details: " + e.toString());
44        }
45    }
46
47    public SubjectKeyIdentifierStructure(
48        PublicKey pubKey)
49        throws InvalidKeyException
50    {
51        super(fromPublicKey(pubKey));
52    }
53}
54