/** Tests {@link ContentInfo#getInstance(InputStream)} method. */
  public void testInit() throws Asn1FormatException, IOException {
    // Make sure illegal arguments are handled correctly
    try {
      ContentInfo.getInstance(null);
      fail("null accepted as content info bytes");
    } catch (IllegalArgumentException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    try {
      InputStream in = new ByteArrayInputStream(CONTENT_INFO);
      in.skip(1);
      ContentInfo.getInstance(in);
      fail("rubbish accepted as content info bytes");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    // Build content info from pre-defined bytes
    InputStream in = new ByteArrayInputStream(CONTENT_INFO);
    ContentInfo.getInstance(in);

    // Build content info using valid components
    DERTaggedObject content = getDerTagged(true, 0, SIGNED_DATA);
    in = getDerStream(CONTENT_TYPE, content);
    ContentInfo.getInstance(in);
  }
  /** Tests {@link ContentInfo#getInstance(InputStream)} method with various content types. */
  public void testInitContentType() throws IOException {
    DERTaggedObject content = getDerTagged(true, 0, SIGNED_DATA);

    // Make sure empty content type is NOT accepted
    try {
      InputStream in = getDerStream(null, content);
      ContentInfo.getInstance(in);
      fail("null accepted as content type");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    // Make sure invalid content type is NOT accepted
    try {
      InputStream in = getDerStream("1.2.840.113549.1.7.3", content);
      ContentInfo.getInstance(in);
      fail("1.2.840.113549.1.7.3 accepted as content type");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }
  }
  /** Tests {@link ContentInfo#getInstance(InputStream)} method with various content values. */
  public void testInitContent() throws IOException {
    // Make sure empty content value is NOT accepted
    try {
      InputStream in = getDerStream(CONTENT_TYPE, null);
      ContentInfo.getInstance(in);
      fail("null accepted as content");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    // Make sure invalid content value is NOT accepted
    try {
      // Using `contentInfo` instead of `signedData`
      DERTaggedObject content = getDerTagged(true, 0, CONTENT_INFO);
      InputStream in = getDerStream(CONTENT_TYPE, content);
      ContentInfo.getInstance(in);
      fail("rubbish accepted as content");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    // Make sure implicitly tagged content is NOT accepted
    try {
      DERTaggedObject content = getDerTagged(false, 0, SIGNED_DATA);
      InputStream in = getDerStream(CONTENT_TYPE, content);
      ContentInfo.getInstance(in);
      // TODO: re-enable check when we upgrade the BC libraries
      // http://www.bouncycastle.org/jira/browse/BJA-259
      // fail("implicitly tagged content accepted");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }

    // Make sure content with invalid tag is NOT accepted
    try {
      DERTaggedObject content = getDerTagged(true, 1, SIGNED_DATA);
      InputStream in = getDerStream(CONTENT_TYPE, content);
      ContentInfo.getInstance(in);
      // TODO: re-enable check when we upgrade the BC libraries
      // http://www.bouncycastle.org/jira/browse/BJA-259
      // fail("content tagged with [1] accepted");
    } catch (Asn1FormatException e) {
      Log.debug("[DBG] (OK) " + e.getMessage());
    }
  }