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

Not working with these test data #31

Open
jumpjack opened this issue Sep 10, 2021 · 0 comments
Open

Not working with these test data #31

jumpjack opened this issue Sep 10, 2021 · 0 comments

Comments

@jumpjack
Copy link

I am experimenting with these test data:

https://github.com/eu-digital-green-certificates/dgc-testdata/blob/main/IT/2DCode/raw/1.json

But I can't get COSE from COMPRESSED, instead I get error:

"uncaught exception: Remaining bytes"

My code:

function vai() {
source = document.getElementById("encoded").value;
console.log("QR string=",source);

// Decode BASE45:
decodedObj = decode45(source);
console.log("Decoded45enc=",decodedObj.enc);
console.log("Decoded45raw=",decodedObj.raw);

decodedObjRawHex = arrayToHex(decodedObj.raw);
console.log("decodedObjRawHex=",decodedObjRawHex);
if (decodedObjRawHex == testData.COMPRESSED) {
	console.log("BASE45 extraction ok");
} else {
	console.log("BASE45 extraction FAILED");
}

toProcess = decodedObj.raw; 

// Convert in string for debug:
converted = convert(toProcess);
document.getElementById("decoded").value = converted;
console.log("converted to string=",converted);
	
// Unzip the decoded:
unzipped =  pako.inflate(toProcess);	
console.log("UNZ:",unzipped);

unzippedHex = arrayToHex(unzipped);
console.log("unzippedHex=",unzippedHex);
console.log("unzippedTest=",testData.COSE);
if (unzippedHex == testData.COSE) {
	console.log("COSE extraction ok");
} else {
	console.log("COSE extraction FAILED");
}

var buffer = new ArrayBuffer(unzipped.length);
unzipped.map(function(value, i){buffer[i] = value});

console.log("Buffer:",buffer);

var decbor = CBOR.decode(buffer);

console.log(decbor);

}

function numHex(s) {
var a = s.toString(16);
if ((a.length % 2) > 0) {
a = "0" + a;
}
return a;
}

function arrayToHex(a) {
final = "";
for (var i=0; i< a.length; i++) {
final += numHex(a[i]);
}
return final;
}

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

1 participant