/** * For constructed field, return a parser for its content. * * @return A parser for the construct. * @throws IOException if DER cannot be parsed. */ public DerParser getParser() throws IOException { if (!isConstructed()) { throw new IOException("Invalid DER: can't parse primitive entity"); //$NON-NLS-1$ } return new DerParser(value); }
@Test public void testCreationDerConstructed() throws Exception { byte[] testValue = {0x00, 0x01, 0x02, 0x03, 0x04}; Asn1Object asn1Object = new Asn1Object(DerParser.NUMERIC_STRING | DER_CONSTRUCTED, 5, testValue); assertEquals(DerParser.NUMERIC_STRING, asn1Object.getType()); assertEquals(5, asn1Object.getLength()); assertEquals(testValue, asn1Object.getValue()); assertTrue(asn1Object.isConstructed()); }
@Test public void testCreationDerNotConstructed() throws Exception { byte[] testValue = {0x00, 0x01, 0x02, 0x03, 0x04}; Asn1Object asn1Object = new Asn1Object(DerParser.NUMERIC_STRING, 5, testValue); assertEquals(DerParser.NUMERIC_STRING, asn1Object.getType()); assertEquals(5, asn1Object.getLength()); assertEquals(testValue, asn1Object.getValue()); assertFalse(asn1Object.isConstructed()); }
/** * For constructed field, return a parser for its content. * * @return A parser for the construct. * @throws IOException if DER cannot be parsed. */ public DerParser getParser() throws IOException { if (!isConstructed()) { throw new IOException("Invalid DER: can't parse primitive entity"); //$NON-NLS-1$ } return new DerParser(value); }