/** Tests the <CODE>write/readOctetString</CODE> methods. */
  @Test(dataProvider = "binaryValues")
  public void testEncodeDecodeOctetStringType(final byte[] b) throws Exception {
    final ByteString bs = ByteString.wrap(b);
    final ByteStringBuilder bsb = new ByteStringBuilder();

    for (final byte type : testTypes) {
      bsb.clear();
      getWriter().writeOctetString(type, bs);

      ASN1Reader r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), b.length);
      assertEquals(r.peekType(), type);
      r.readOctetString(bsb);
      assertTrue(bs.equals(bsb));

      bsb.clear();
      getWriter().writeOctetString(type, b, 0, b.length);

      r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), b.length);
      assertEquals(r.peekType(), type);
      r.readOctetString(bsb);
      assertTrue(bs.equals(bsb));
    }
  }
  /** Tests the <CODE>write/readOctetString</CODE> methods. */
  @Test(dataProvider = "binaryValues")
  public void testEncodeDecodeOctetString(final byte[] b) throws Exception {
    final ByteString bs = ByteString.wrap(b);

    getWriter().writeOctetString(bs);

    ASN1Reader r = getReader(getEncodedBytes());
    assertEquals(r.peekLength(), b.length);
    assertEquals(r.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    assertTrue(bs.equals(r.readOctetString()));

    getWriter().writeOctetString(b, 0, b.length);

    r = getReader(getEncodedBytes());
    assertEquals(r.peekLength(), b.length);
    assertEquals(r.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
    assertTrue(bs.equals(r.readOctetString()));
  }
  /** Tests the <CODE>write/readOctetString</CODE> methods. */
  @Test
  public void testEncodeDecodeOctetStringOffLen() throws Exception {
    final byte[] b = new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};

    for (int i = 0; i < 5; i += 2) {
      final byte[] bsb = new byte[3];
      System.arraycopy(b, i, bsb, 0, 3);
      final ByteString bs = ByteString.wrap(bsb);
      getWriter().writeOctetString(b, i, 3);

      final ASN1Reader r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), 3);
      assertEquals(r.peekType(), ASN1.UNIVERSAL_OCTET_STRING_TYPE);
      assertTrue(bs.equals(r.readOctetString()));
    }
  }