From ff7e3432dc2db58aed49eca8b9a1fa22ad2a822b Mon Sep 17 00:00:00 2001 From: CGantert345 <57003061+CGantert345@users.noreply.github.com> Date: Wed, 24 Nov 2021 12:42:11 +0100 Subject: removed obsolete code --- .../org/uic/barcode/asn1/uper/BigIntCoder.java | 97 ---------------------- .../org/uic/barcode/asn1/uper/UperEncoder.java | 2 - 2 files changed, 99 deletions(-) delete mode 100644 src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java diff --git a/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java b/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java deleted file mode 100644 index 94e4b05..0000000 --- a/src/main/java/org/uic/barcode/asn1/uper/BigIntCoder.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.uic.barcode.asn1.uper; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; -import java.math.BigInteger; - -import org.uic.barcode.asn1.datatypes.Asn1BigInteger; -import org.uic.barcode.asn1.datatypes.Asn1Default; -import org.uic.barcode.asn1.datatypes.IntRange; - -class BigIntCoder implements Encoder, Decoder { - - @Override public boolean canDecode(Class classOfT, Annotation[] extraAnnotations) { - return Asn1BigInteger.class.isAssignableFrom(classOfT); - } - - @Override public T decode(BitBuffer bitbuffer, - Class classOfT, Field f, - Annotation[] extraAnnotations) { - AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(), - extraAnnotations); - - String pos = String.format("%d.%d", bitbuffer.position()/8 , bitbuffer.position() % 8); - UperEncoder.logger.debug(String.format("Position %s BIG INT",pos)); - IntRange intRange = annotations.getAnnotation(IntRange.class); - if (intRange != null && intRange.maxValue() > 0) { - throw new UnsupportedOperationException("Big int with upper range is not supported yet"); - } - - int lengthInOctets = (int) UperEncoder.decodeLengthDeterminant(bitbuffer); - BitBuffer valueBits = ByteBitBuffer.allocate(lengthInOctets * 8); - for (int i = 0; i < lengthInOctets * 8; i++) { - valueBits.put(bitbuffer.get()); - } - valueBits.flip(); - BigInteger resultValue = new BigInteger(+1, valueBits.array()); - UperEncoder.logger.debug(String.format("big int Decoded as %s", resultValue)); - - - //CG support for int range - if (intRange != null){ - resultValue.add(BigInteger.valueOf(intRange.minValue())); - } - - - return UperEncoder.instantiate(classOfT, resultValue); - } - - @Override public boolean canEncode(T obj, Annotation[] extraAnnotations) { - return obj instanceof Asn1BigInteger; - } - - @Override public void encode(BitBuffer bitbuffer, T obj, Annotation[] extraAnnotations) throws Asn1EncodingException { - Class type = obj.getClass(); - AnnotationStore annotations = new AnnotationStore(type.getAnnotations(), extraAnnotations); - IntRange range = annotations.getAnnotation(IntRange.class); - - //CG implementation with lower range limit added - BigInteger bint = ((Asn1BigInteger) obj).toBigInteger(); - if (range != null) { - throw new UnsupportedOperationException("Asn1 BigInteger with range is not supported"); - } - byte[] array = bint.toByteArray(); - int lengthInOctets = array.length; - int position1 = bitbuffer.position(); - try { - UperEncoder.encodeLengthDeterminant(bitbuffer, lengthInOctets); - } catch (Asn1EncodingException e) { - throw new Asn1EncodingException(" length determinant of " + type.getName(), e); - } - int position2 = bitbuffer.position(); - for (byte b : array) { - bitbuffer.putByte(b); - } - UperEncoder.logger.debug(String.format("Big Int(%s): len %s, val %s", obj, - bitbuffer.toBooleanString(position1, position2 - position1), - bitbuffer.toBooleanStringFromPosition(position2))); - return; - } - - @Override - public T getDefault(Class classOfT, Annotation[] extraAnnotations) { - AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(), extraAnnotations); - Asn1Default defaultAnnotation = annotations.getAnnotation(Asn1Default.class); - if (defaultAnnotation == null) return null; - //check whether the class has a constructor for numeric types - String valueString = defaultAnnotation.value(); - long value = Long.parseLong(valueString); - UperEncoder.logger.debug(String.format("Default INTEGER: %d",value )); - - @SuppressWarnings("unchecked") - T t = (T) new Asn1BigInteger(value); - return t; - - } - -} \ No newline at end of file diff --git a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java index 5956054..bba64e2 100644 --- a/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java +++ b/src/main/java/org/uic/barcode/asn1/uper/UperEncoder.java @@ -162,7 +162,6 @@ public final class UperEncoder { static { encoders.add(new IntCoder()); - //encoders.add(new BigIntCoder()); encoders.add(new ByteCoder()); encoders.add(new BooleanCoder()); encoders.add(new SequenceCoder()); @@ -173,7 +172,6 @@ public final class UperEncoder { encoders.add(new StringCoder()); decoders.add(new IntCoder()); - //decoders.add(new BigIntCoder()); decoders.add(new ByteCoder()); decoders.add(new BooleanCoder()); decoders.add(new SequenceCoder()); -- cgit v1.2.3