|
10 | 10 | import java.util.Set;
|
11 | 11 | import java.util.StringTokenizer;
|
12 | 12 |
|
13 |
| -import org.bouncycastle.asn1.ASN1InputStream; |
| 13 | +import org.bouncycastle.asn1.ASN1BitString; |
14 | 14 | import org.bouncycastle.asn1.ASN1Integer;
|
15 | 15 | import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
16 | 16 | import org.bouncycastle.asn1.ASN1Primitive;
|
@@ -110,22 +110,19 @@ public Object readObject()
|
110 | 110 | throws IOException
|
111 | 111 | {
|
112 | 112 | PemObject obj = readPemObject();
|
| 113 | + if (obj == null) |
| 114 | + { |
| 115 | + return null; |
| 116 | + } |
113 | 117 |
|
114 |
| - if (obj != null) |
| 118 | + String type = obj.getType(); |
| 119 | + Object pemObjectParser = parsers.get(type); |
| 120 | + if (pemObjectParser == null) |
115 | 121 | {
|
116 |
| - String type = obj.getType(); |
117 |
| - Object pemObjectParser = parsers.get(type); |
118 |
| - if (pemObjectParser != null) |
119 |
| - { |
120 |
| - return ((PemObjectParser)pemObjectParser).parseObject(obj); |
121 |
| - } |
122 |
| - else |
123 |
| - { |
124 |
| - throw new IOException("unrecognised object: " + type); |
125 |
| - } |
| 122 | + throw new IOException("unrecognised object: " + type); |
126 | 123 | }
|
127 | 124 |
|
128 |
| - return null; |
| 125 | + return ((PemObjectParser)pemObjectParser).parseObject(obj); |
129 | 126 | }
|
130 | 127 |
|
131 | 128 | /**
|
@@ -268,16 +265,14 @@ public PEMKeyPair parse(byte[] encoding)
|
268 | 265 | pKey.getParametersObject());
|
269 | 266 | PrivateKeyInfo privInfo = new PrivateKeyInfo(algId, pKey);
|
270 | 267 |
|
271 |
| - if (pKey.getPublicKey() != null) |
| 268 | + ASN1BitString publicKey = pKey.getPublicKey(); |
| 269 | + SubjectPublicKeyInfo pubInfo = null; |
| 270 | + if (publicKey != null) |
272 | 271 | {
|
273 |
| - SubjectPublicKeyInfo pubInfo = new SubjectPublicKeyInfo(algId, pKey.getPublicKey().getBytes()); |
274 |
| - |
275 |
| - return new PEMKeyPair(pubInfo, privInfo); |
276 |
| - } |
277 |
| - else |
278 |
| - { |
279 |
| - return new PEMKeyPair(null, privInfo); |
| 272 | + pubInfo = new SubjectPublicKeyInfo(algId, publicKey.getBytes()); |
280 | 273 | }
|
| 274 | + |
| 275 | + return new PEMKeyPair(pubInfo, privInfo); |
281 | 276 | }
|
282 | 277 | catch (IOException e)
|
283 | 278 | {
|
@@ -353,9 +348,10 @@ public Object parseObject(PemObject obj)
|
353 | 348 | {
|
354 | 349 | try
|
355 | 350 | {
|
| 351 | + AlgorithmIdentifier algId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE); |
356 | 352 | RSAPublicKey rsaPubStructure = RSAPublicKey.getInstance(obj.getContent());
|
357 | 353 |
|
358 |
| - return new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), rsaPubStructure); |
| 354 | + return new SubjectPublicKeyInfo(algId, rsaPubStructure); |
359 | 355 | }
|
360 | 356 | catch (IOException e)
|
361 | 357 | {
|
@@ -475,9 +471,7 @@ public Object parseObject(PemObject obj)
|
475 | 471 | {
|
476 | 472 | try
|
477 | 473 | {
|
478 |
| - ASN1InputStream aIn = new ASN1InputStream(obj.getContent()); |
479 |
| - |
480 |
| - return ContentInfo.getInstance(aIn.readObject()); |
| 474 | + return ContentInfo.getInstance(obj.getContent()); |
481 | 475 | }
|
482 | 476 | catch (Exception e)
|
483 | 477 | {
|
@@ -508,7 +502,7 @@ public Object parseObject(PemObject obj)
|
508 | 502 |
|
509 | 503 | if (param instanceof ASN1ObjectIdentifier)
|
510 | 504 | {
|
511 |
| - return ASN1Primitive.fromByteArray(obj.getContent()); |
| 505 | + return param; |
512 | 506 | }
|
513 | 507 | else if (param instanceof ASN1Sequence)
|
514 | 508 | {
|
|
0 commit comments