use of es.gob.jmulticard.asn1.Tlv in project bgpcep by opendaylight.
the class AbstractBmpMessageWithTlvParser method parseTlvs.
protected final void parseTlvs(final T builder, final ByteBuf bytes) throws BmpDeserializationException {
Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null.");
if (!bytes.isReadable()) {
return;
}
while (bytes.isReadable()) {
final int type = bytes.readUnsignedShort();
final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
throw new BmpDeserializationException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + ".");
}
final ByteBuf tlvBytes = bytes.readSlice(length);
LOG.trace("Parsing BMP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
final Tlv tlv = this.tlvRegistry.parseTlv(type, tlvBytes);
if (tlv != null) {
LOG.trace("Parsed BMP TLV {}.", tlv);
addTlv(builder, tlv);
}
}
}
use of es.gob.jmulticard.asn1.Tlv in project bgpcep by opendaylight.
the class SimpleBmpTlvRegistryTest method testParseTlv.
@Test
public void testParseTlv() throws BmpDeserializationException {
final Tlv output = this.bmpTlvRegistry.parseTlv(DESCRIPTION_TLV_TYPE, this.input);
assertNotNull(output);
assertTrue(output instanceof MockDescriptionTlv);
final ByteBuf aggregator = Unpooled.EMPTY_BUFFER;
this.bmpTlvRegistry.serializeTlv(output, aggregator);
Mockito.verify(this.descriptionTlvSerializer).serializeTlv(output, aggregator);
}
use of es.gob.jmulticard.asn1.Tlv in project bgpcep by opendaylight.
the class AbstractObjectWithTlvsParser method parseTlvs.
protected final void parseTlvs(final T builder, final ByteBuf bytes) throws PCEPDeserializerException {
Preconditions.checkArgument(bytes != null, "Array of bytes is mandatory. Can't be null.");
if (!bytes.isReadable()) {
return;
}
final List<VendorInformationTlv> viTlvs = Lists.newArrayList();
while (bytes.isReadable()) {
final int type = bytes.readUnsignedShort();
final int length = bytes.readUnsignedShort();
if (length > bytes.readableBytes()) {
throw new PCEPDeserializerException("Wrong length specified. Passed: " + length + "; Expected: <= " + bytes.readableBytes() + ".");
}
final ByteBuf tlvBytes = bytes.readSlice(length);
LOG.trace("Parsing PCEP TLV : {}", ByteBufUtil.hexDump(tlvBytes));
if (VendorInformationUtil.isVendorInformationTlv(type)) {
final EnterpriseNumber enterpriseNumber = new EnterpriseNumber(tlvBytes.readUnsignedInt());
final Optional<VendorInformationTlv> viTlv = this.viTlvReg.parseVendorInformationTlv(enterpriseNumber, tlvBytes);
if (viTlv.isPresent()) {
LOG.trace("Parsed VENDOR-INFORMATION TLV {}.", viTlv.get());
viTlvs.add(viTlv.get());
}
} else {
final Tlv tlv = this.tlvReg.parseTlv(type, tlvBytes);
if (tlv != null) {
LOG.trace("Parsed PCEP TLV {}.", tlv);
addTlv(builder, tlv);
}
}
bytes.skipBytes(TlvUtil.getPadding(TlvUtil.HEADER_SIZE + length, TlvUtil.PADDED_TO));
}
addVendorInformationTlvs(builder, viTlvs);
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class TestTlvCreation method testTlv.
/**
* Prueba la creación de TLV con volcados de CDF.
* @throws Exception en caso de cualquier tipo de error
*/
public static void testTlv() throws Exception {
byte[] cdfdata;
for (final String element : TEST_FILES) {
cdfdata = getDataFromInputStream(ClassLoader.getSystemResourceAsStream(element));
final Tlv tlv = new Tlv(cdfdata);
Assert.assertNotNull(tlv);
LOGGER.info(tlv.toString());
// $NON-NLS-1$
LOGGER.info("\n\nProbando " + element);
// $NON-NLS-1$ //$NON-NLS-2$
LOGGER.info("\nTLV completo (" + Integer.toString(tlv.getBytes().length) + "):");
LOGGER.info(HexUtils.hexify(tlv.getBytes(), true));
// $NON-NLS-1$
LOGGER.info("\nTipo TLV:");
LOGGER.info(HexUtils.hexify(new byte[] { tlv.getTag() }, true));
// $NON-NLS-1$
LOGGER.info("\nLongitud TLV:");
LOGGER.info(Integer.toString(tlv.getLength()));
// $NON-NLS-1$ //$NON-NLS-2$
LOGGER.info("\nValor TLV (" + Integer.toString(tlv.getValue().length) + "):");
LOGGER.info(HexUtils.hexify(tlv.getValue(), true));
}
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class TestAsn1SimpleTypes method testUtf8StringCreationWithBadData.
/**
* Prueba la creació de un tipo <code>UTF8String</code> con datos incorrectos.
* @throws TlvException Si no se puede crear el TLV.
*/
@Test
@SuppressWarnings("static-method")
public void testUtf8StringCreationWithBadData() throws TlvException {
final Utf8String u = new Utf8String();
try {
u.setDerValue(new byte[] { (byte) 0x00, (byte) 0x01, (byte) 0xff });
} catch (final Asn1Exception e) {
// $NON-NLS-1$
System.out.println("Fallo esperado: " + e);
return;
}
// $NON-NLS-1$
Assert.fail("Tendria que haber saltado un Asn1Exception");
}
Aggregations