paroga/cbor-js

Not working with these test data

jumpjack opened this issue · 0 comments

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;
}