Search in sources :

Example 1 with Tlv

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);
        }
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Tlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv)

Example 2 with 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);
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) Tlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv) Test(org.junit.Test)

Example 3 with Tlv

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);
}
Also used : VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) EnterpriseNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber) ByteBuf(io.netty.buffer.ByteBuf) VendorInformationTlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv) Tlv(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv)

Example 4 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class TestTlvCreation method testTlv.

/**
 * Prueba la creaci&oacute;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));
    }
}
Also used : Tlv(es.gob.jmulticard.asn1.Tlv)

Example 5 with Tlv

use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.

the class TestAsn1SimpleTypes method testUtf8StringCreationWithBadData.

/**
 * Prueba la creaci&oacute; 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");
}
Also used : Utf8String(es.gob.jmulticard.asn1.der.Utf8String) Asn1Exception(es.gob.jmulticard.asn1.Asn1Exception) Test(org.junit.Test)

Aggregations

Tlv (es.gob.jmulticard.asn1.Tlv)11 Asn1Exception (es.gob.jmulticard.asn1.Asn1Exception)6 TlvException (es.gob.jmulticard.asn1.TlvException)6 DecoderObject (es.gob.jmulticard.asn1.DecoderObject)4 ByteBuf (io.netty.buffer.ByteBuf)3 Test (org.junit.Test)3 ResponseApdu (es.gob.jmulticard.apdu.ResponseApdu)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Tlv (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.message.rev171207.Tlv)2 CommandApdu (es.gob.jmulticard.apdu.CommandApdu)1 ApduConnectionException (es.gob.jmulticard.apdu.connection.ApduConnectionException)1 SecureChannelException (es.gob.jmulticard.apdu.connection.cwa14890.SecureChannelException)1 GeneralAuthenticateApduCommand (es.gob.jmulticard.apdu.iso7816four.GeneralAuthenticateApduCommand)1 MseSetPaceAlgorithmApduCommand (es.gob.jmulticard.apdu.iso7816four.pace.MseSetPaceAlgorithmApduCommand)1 BerTlv (es.gob.jmulticard.asn1.bertlv.BerTlv)1 BitString (es.gob.jmulticard.asn1.der.BitString)1 DerBoolean (es.gob.jmulticard.asn1.der.DerBoolean)1 Utf8String (es.gob.jmulticard.asn1.der.Utf8String)1 AccessFlags (es.gob.jmulticard.asn1.der.pkcs15.AccessFlags)1 AmAESCrypto (es.gob.jmulticard.de.tsenger.androsmex.crypto.AmAESCrypto)1