コード例 #1
0
  /** Tests the <CODE>write/readNull</CODE> methods. */
  @Test
  public void testEncodeDecodeNull() throws Exception {
    getWriter().writeNull();

    final ASN1Reader r = getReader(getEncodedBytes());
    assertEquals(r.peekLength(), 0);
    assertEquals(r.peekType(), ASN1.UNIVERSAL_NULL_TYPE);
    r.readNull();
  }
コード例 #2
0
  @Test
  public void testEncodeDecodeSequence() throws Exception {
    final ASN1Writer writer = getWriter();

    writer.writeStartSequence();

    writer.writeBoolean(true);
    writer.writeBoolean(false);
    writer.writeInteger(0);
    writer.writeInteger(10L);
    writer.writeNull();
    writer.writeOctetString("test value");
    writer.writeOctetString("skip value");

    writer.writeStartSequence();
    writer.writeOctetString("nested sequence");
    writer.writeEndSequence();

    writer.writeStartSet();
    writer.writeOctetString("nested set");
    writer.writeEndSet();

    writer.writeEndSequence();

    final ASN1Reader reader = getReader(getEncodedBytes());
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_SEQUENCE_TYPE);
    assertEquals(reader.peekLength(), 71);

    assertTrue(reader.hasNextElement());
    reader.readStartSequence();
    assertTrue(reader.hasNextElement());

    assertEquals(true, reader.readBoolean());
    assertEquals(false, reader.readBoolean());
    assertEquals(0, reader.readInteger());
    assertEquals(10, reader.readInteger());
    reader.readNull();
    assertEquals("test value", reader.readOctetStringAsString());
    reader.skipElement();

    assertEquals(reader.peekLength(), 17);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_SEQUENCE_TYPE);
    reader.readStartSequence();
    assertEquals("nested sequence", reader.readOctetStringAsString());
    reader.readEndSequence();

    assertEquals(reader.peekLength(), 12);
    assertEquals(reader.peekType(), ASN1.UNIVERSAL_SET_TYPE);
    reader.readStartSequence();
    assertEquals("nested set", reader.readOctetStringAsString());
    reader.readEndSequence();

    assertFalse(reader.hasNextElement());
    reader.readEndSequence();
    assertFalse(reader.elementAvailable());
  }
コード例 #3
0
  /** Tests the <CODE>write/readNull</CODE> methods. */
  @Test
  public void testEncodeDecodeNullType() throws Exception {
    for (final byte type : testTypes) {
      getWriter().writeNull(type);

      final ASN1Reader r = getReader(getEncodedBytes());
      assertEquals(r.peekLength(), 0);
      assertEquals(r.peekType(), type);
      r.readNull();
    }
  }