X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fasn1%2Fx509%2FSubjectPublicKeyInfo.java;fp=src%2Forg%2Fbouncycastle%2Fasn1%2Fx509%2FSubjectPublicKeyInfo.java;h=53541b9b8973a4c2f4fdcfbe2e6d4b58c5afd578;hb=d70f271afd972a3bdeba9ee54b1e9a3334e6fe4b;hp=2e658819dc56e148ca764b5bfbf6bc71c1486920;hpb=3f13b8f2e9c92b428dc237327f3e86353902ac29;p=org.ibex.core.git diff --git a/src/org/bouncycastle/asn1/x509/SubjectPublicKeyInfo.java b/src/org/bouncycastle/asn1/x509/SubjectPublicKeyInfo.java index 2e65881..53541b9 100644 --- a/src/org/bouncycastle/asn1/x509/SubjectPublicKeyInfo.java +++ b/src/org/bouncycastle/asn1/x509/SubjectPublicKeyInfo.java @@ -17,36 +17,53 @@ public class SubjectPublicKeyInfo implements DEREncodable { private AlgorithmIdentifier algId; - private DERObject pubKey; + private DERBitString keyData; + + public static SubjectPublicKeyInfo getInstance( + ASN1TaggedObject obj, + boolean explicit) + { + return getInstance(ASN1Sequence.getInstance(obj, explicit)); + } + + public static SubjectPublicKeyInfo getInstance( + Object obj) + { + if (obj instanceof SubjectPublicKeyInfo) + { + return (SubjectPublicKeyInfo)obj; + } + else if (obj instanceof ASN1Sequence) + { + return new SubjectPublicKeyInfo((ASN1Sequence)obj); + } + + throw new IllegalArgumentException("unknown object in factory"); + } public SubjectPublicKeyInfo( AlgorithmIdentifier algId, - DERObject publicKey) + DEREncodable publicKey) { - this.pubKey = publicKey; + this.keyData = new DERBitString(publicKey); this.algId = algId; } public SubjectPublicKeyInfo( - DERConstructedSequence seq) + AlgorithmIdentifier algId, + byte[] publicKey) { - Enumeration e = seq.getObjects(); - - algId = new AlgorithmIdentifier((DERConstructedSequence)e.nextElement()); - - byte[] keyData = ((DERBitString)e.nextElement()).getBytes(); + this.keyData = new DERBitString(publicKey); + this.algId = algId; + } - try - { - ByteArrayInputStream bIn = new ByteArrayInputStream(keyData); - DERInputStream dIn = new DERInputStream(bIn); + public SubjectPublicKeyInfo( + ASN1Sequence seq) + { + Enumeration e = seq.getObjects(); - pubKey = (DERObject)dIn.readObject(); - } - catch (IOException ex) - { - throw new IllegalArgumentException("error recovering public key"); - } + this.algId = AlgorithmIdentifier.getInstance(e.nextElement()); + this.keyData = (DERBitString)e.nextElement(); } public AlgorithmIdentifier getAlgorithmId() @@ -54,9 +71,28 @@ public class SubjectPublicKeyInfo return algId; } + /** + * for when the public key is an encoded object - if the bitstring + * can't be decoded this routine throws an IOException. + * + * @exception IOException - if the bit string doesn't represent a DER + * encoded object. + */ public DERObject getPublicKey() + throws IOException + { + ByteArrayInputStream bIn = new ByteArrayInputStream(keyData.getBytes()); + DERInputStream dIn = new DERInputStream(bIn); + + return dIn.readObject(); + } + + /** + * for when the public key is raw bits... + */ + public DERBitString getPublicKeyData() { - return pubKey; + return keyData; } /** @@ -71,7 +107,7 @@ public class SubjectPublicKeyInfo DERConstructedSequence seq = new DERConstructedSequence(); seq.addObject(algId); - seq.addObject(new DERBitString(pubKey)); + seq.addObject(keyData); return seq; }