• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  package org.bouncycastle.asn1;
2  
3  import java.io.IOException;
4  import java.io.InputStream;
5  
6  public class BERTaggedObjectParser
7      implements ASN1TaggedObjectParser
8  {
9      private boolean _constructed;
10      private int _tagNumber;
11      private ASN1StreamParser _parser;
12  
13      /**
14       * @deprecated
15       */
BERTaggedObjectParser( int baseTag, int tagNumber, InputStream contentStream)16      protected BERTaggedObjectParser(
17          int         baseTag,
18          int         tagNumber,
19          InputStream contentStream)
20      {
21          this((baseTag & DERTags.CONSTRUCTED) != 0, tagNumber, new ASN1StreamParser(contentStream));
22      }
23  
BERTaggedObjectParser( boolean constructed, int tagNumber, ASN1StreamParser parser)24      BERTaggedObjectParser(
25          boolean             constructed,
26          int                 tagNumber,
27          ASN1StreamParser    parser)
28      {
29          _constructed = constructed;
30          _tagNumber = tagNumber;
31          _parser = parser;
32      }
33  
isConstructed()34      public boolean isConstructed()
35      {
36          return _constructed;
37      }
38  
getTagNo()39      public int getTagNo()
40      {
41          return _tagNumber;
42      }
43  
getObjectParser( int tag, boolean isExplicit)44      public DEREncodable getObjectParser(
45          int     tag,
46          boolean isExplicit)
47          throws IOException
48      {
49          if (isExplicit)
50          {
51              if (!_constructed)
52              {
53                  throw new IOException("Explicit tags must be constructed (see X.690 8.14.2)");
54              }
55              return _parser.readObject();
56          }
57  
58          return _parser.readImplicit(_constructed, tag);
59      }
60  
getLoadedObject()61      public DERObject getLoadedObject()
62          throws IOException
63      {
64          return _parser.readTaggedObject(_constructed, _tagNumber);
65      }
66  
getDERObject()67      public DERObject getDERObject()
68      {
69          try
70          {
71              return this.getLoadedObject();
72          }
73          catch (IOException e)
74          {
75              throw new ASN1ParsingException(e.getMessage());
76          }
77      }
78  }
79