diff options
Diffstat (limited to 'crypto/src/x509/X509AttrCertParser.cs')
-rw-r--r-- | crypto/src/x509/X509AttrCertParser.cs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/crypto/src/x509/X509AttrCertParser.cs b/crypto/src/x509/X509AttrCertParser.cs index a5c07362e..ce708ed8d 100644 --- a/crypto/src/x509/X509AttrCertParser.cs +++ b/crypto/src/x509/X509AttrCertParser.cs @@ -131,20 +131,27 @@ namespace Org.BouncyCastle.X509 return null; } - PushbackStream pis = new PushbackStream(inStream); - int tag = pis.ReadByte(); - - if (tag < 0) - return null; - - pis.Unread(tag); - - if (tag != 0x30) // assume ascii PEM encoded. + int tag = inStream.ReadByte(); + if (tag < 0) + return null; + + if (inStream.CanSeek) + { + inStream.Seek(-1L, SeekOrigin.Current); + } + else + { + PushbackStream pis = new PushbackStream(inStream); + pis.Unread(tag); + inStream = pis; + } + + if (tag != 0x30) // assume ascii PEM encoded. { - return ReadPemCertificate(pis); + return ReadPemCertificate(inStream); } - return ReadDerCertificate(new Asn1InputStream(pis)); + return ReadDerCertificate(new Asn1InputStream(inStream)); } catch (Exception e) { |