Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COERInteger encode negative number error #8

Open
Eivense opened this issue Sep 24, 2019 · 2 comments
Open

COERInteger encode negative number error #8

Eivense opened this issue Sep 24, 2019 · 2 comments

Comments

@Eivense
Copy link

Eivense commented Sep 24, 2019

Hi,pvendil @pvendil

l found when the value is negative (e.g. -10000),it will be encode to 0000D8F0.
When decoding, it is calculated as 55536,-10000 need to be encoded to FFFFD8F0
When the value is negative,the buffer need to be filled with 0xff

private void serializeSigned(DataOutputStream out) throws IOException {
		byte[] val = value.toByteArray();

		int signOctet = 0;
		if(val[0] == 0x00 && val.length > 1){
			signOctet++;
		}
		
		if(isSignedAndBetween(NEGATIVE_TWO_PWR_63, TWO_PWR_63_MINUS_1)){
			byte[] buffer = new byte[getSignedBufferSize()];
                        // if value is negative buffer need to be filled with 0xff
			System.arraycopy(val, signOctet, buffer, buffer.length - (val.length -signOctet), val.length -signOctet);
			out.write(buffer);
		}else{
			COEREncodeHelper.writeLengthDeterminant(val.length-signOctet, out);
			out.write(val, signOctet, val.length -signOctet);
		}
	}
@pvendil
Copy link
Contributor

pvendil commented Sep 25, 2019

Hi,

It seems you are right, I will look into this, hopefully in the coming week with a fix for this.

@pvendil
Copy link
Contributor

pvendil commented Jan 9, 2020

Hi sorry for late reply, I have now update the code to encode COER integers properly. And it included in release 2.0.0-Beta4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants