beanit / asn1bean

ASN1bean (formerly known as jASN1) is a Java ASN.1 BER and DER encoding/decoding library
https://www.beanit.com/asn1/
Apache License 2.0
110 stars 45 forks source link

Add decimal BER REAL decoding #44

Closed bibmaster closed 1 year ago

bibmaster commented 2 years ago

8.5.5 Bit 8 of the first contents octet shall be set as follows: ... b) if bit 8 = 0 and bit 7 = 0, then the decimal encoding specified in 8.5.7 applies;

8.5.7 When decimal encoding is used (bits 8 to 7 = 00), all the contents octets following the first contents octet form a field, as the term is used in ISO 6093, of a length chosen by the sender, and encoded according to ISO 6093. The choice of ISO 6093 number representation is specified by bits 6 to 1 of the first contents octet as follows:

Bits 6 to 1 Number representation:

00 0001 ISO 6093 NR1 form
00 0010 ISO 6093 NR2 form
00 0011 ISO 6093 NR3 form

ISO 6093 simply describes the floating point string representation. NR1 - no decimal separator, NR2 - decimal separator, NR3 - scientific notation. All of these forms can be parsed with parseDouble. The standard allows you to use a comma as a separator, parseDouble is not locale aware, so ',' can be simply replaced with '.'.

ukarim commented 1 year ago

Any updates on this? Would be very great to have this in master

ukarim commented 1 year ago

@bibmaster This part contains two reallocations

byte[] valueBytes = Arrays.copyOfRange(byteCode, 1, byteCode.length);
String str = new String(valueBytes, StandardCharsets.US_ASCII);

Maybe replace it with

String str = new String(byteCode, 1, byteCode.length - 1, StandardCharsets.US_ASCII);
sfeuerhahn commented 1 year ago

yes, this looks good. Thanks for contribution and sorry for taking so long.