use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class MseSetComputationApduCommand method createDst.
private static byte[] createDst(final byte[] privateKeyReference, final byte[] algorithmReference) {
if (privateKeyReference == null) {
throw new IllegalArgumentException(// $NON-NLS-1$
"La referencia a la clave privada no puede ser nula");
}
final Tlv prkRefTlv = new Tlv(PRIVATE_KEY_REFERENCE, privateKeyReference);
Tlv algRefTlv = null;
if (algorithmReference != null) {
algRefTlv = new Tlv(ALGORITHM_REFERENCE, algorithmReference);
}
final ByteArrayOutputStream dstData = new ByteArrayOutputStream();
try {
dstData.write(prkRefTlv.getBytes());
if (algRefTlv != null) {
dstData.write(algRefTlv.getBytes());
}
} catch (final Exception e) {
throw new IllegalStateException(// $NON-NLS-1$
"Error creando el cuerpo del DST: " + e, // $NON-NLS-1$
e);
}
return dstData.toByteArray();
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class ContextSpecific method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
final Tlv tlv = new Tlv(this.getRawDerValue());
final DecoderObject tmpDo;
try {
tmpDo = this.elementType.getConstructor().newInstance();
} catch (final Exception e) {
throw new Asn1Exception(// $NON-NLS-1$ //$NON-NLS-2$
"No se ha podido instanciar un " + this.elementType.getName() + " en el contexto especifico: " + e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
tmpDo.setDerValue(tlv.getValue());
this.object = tmpDo;
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class DerBoolean method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
final Tlv tmpTlv = new Tlv(this.getRawDerValue());
checkTag(tmpTlv.getTag());
this.booleanValue = Boolean.valueOf(tmpTlv.getValue()[0] == (byte) 0x00);
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class OctectString method decodeValue.
@Override
protected void decodeValue() throws TlvException {
final Tlv tlv = new Tlv(this.getRawDerValue());
if (TAG_OCTECTSTRING != tlv.getTag()) {
throw new TlvException(// $NON-NLS-1$
"Se esperaba un TLV de tipo OctectString pero se ha encontrado uno de tipo " + HexUtils.hexify(new byte[] { tlv.getTag() }, false));
}
this.value = tlv.getValue();
}
use of es.gob.jmulticard.asn1.Tlv in project jmulticard by ctt-gob-es.
the class Record method decodeValue.
@Override
protected void decodeValue() throws Asn1Exception, TlvException {
if (getRawDerValue().length == 0) {
// $NON-NLS-1$
throw new Asn1Exception("El valor del objeto ASN.1 esta vacio");
}
int offset = 0;
Tlv tlv;
byte[] remainingBytes;
DecoderObject tmpDo;
for (int i = 0; i < this.elementsTypes.length; i++) {
try {
remainingBytes = new byte[getRawDerValue().length - offset];
System.arraycopy(getRawDerValue(), offset, remainingBytes, 0, remainingBytes.length);
tlv = new Tlv(remainingBytes);
try {
tmpDo = this.elementsTypes[i].getElementType().getConstructor().newInstance();
} catch (final Exception e) {
throw new Asn1Exception(// $NON-NLS-1$
"No se ha podido instanciar un " + this.elementsTypes[i].getElementType().getName() + " en la posicion " + Integer.toString(i) + " del registro: " + // $NON-NLS-1$ //$NON-NLS-2$
e, // $NON-NLS-1$ //$NON-NLS-2$
e);
}
tmpDo.checkTag(tlv.getTag());
} catch (final Exception e) {
if (this.elementsTypes[i].isOptional()) {
// Como no ha avanzado el offset, se reutilizara el tipo en el proximo elemento
continue;
}
// $NON-NLS-1$ //$NON-NLS-2$
throw new Asn1Exception("Error en el elemento " + i + " del registro ASN.1: " + e, e);
}
offset = offset + tlv.getBytes().length;
tmpDo.setDerValue(tlv.getBytes());
this.elements.add(tmpDo);
}
}
Aggregations