Giter Site home page Giter Site logo

delphicbor's People

Contributors

mikerabat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

delphicbor's Issues

Issue in encoding string-types

when encoding longer structures, the length-bytes must be in reversed order. this is implemented correctly for arrays, maps etc. but not for string-types.
the calls to "RevertByteOrder(@dwLen, sizeof(dwLen));" are missing from the routines "TCborUtf8String.CBOREncode and "TCborByteString.CBOREncode". (must be included twice in each class, for "word" and "longword")

CBOR library for Delphi is returning a different answer than Nodejs

Delphi result at map position 192 text converted to Ascii 101,110,86,84,108,118,79,82,70,53,102,111,82,68,103,99,57,70,89,120,84,67,53,77,54,48,118,55,102,110,88,83,113,116, 116,75,99,52,117,78,84,55,53,101,51,118,115,82,95,104,85,48,75,65,101,119,116,95,107,50,108,74,102,45,84,81,122,65,122,121,109,105,50,101,107,90,85,67,49,118,116,80,108,70,87,103,77

Nodejs result and the expected answer at map position 192 122, 117, 83, 150, 243, 145, 23, 151, 232, 68, 56, 28, 244, 86, 49, 76, 46, 76, 235, 75, 251, 126, 117, 210, 170, 219, 74, 115, 139, 141, 79, 190, 94,222, 251, 17, 254, 21, 52, 40, 7, 176, 183, 249, 54, 148, 151, 254, 77, 12, 192, 207, 41, 162, 217,233, 25, 80, 45, 111, 180, 249, 69, 90, 3

Decoding this QR string to a map need the result at 192 3ECQDIYBQEIRQ5MBDBXBQ7FIAGBRCFQUDBYIEA2Q2C5A4FSECFA4PKHNWFC5NRLIMIMHF JIYOQMJMGFWDJRDW3F2DC7BRRAYYBMEC6TVKOLPHEIXS7UEIOA46RLDCTBOJTVUX636 OXJKVW2KOOFY2T56L3PPWEP6CU2CQB5QW74TNFEX7ZGQZQGPFGRNT2IZKAWW7NHZIVN AGGGCQMMQIAKYELWQDEP3OFVEUZQ6YX5WINVT6YRF5P6BBJ7NUYGSWS5V435T5T53CI D7LARO2AMR7NYWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4MHLAQYN QMIEGE6UIMIUWCXPLMQKANEAAKRQ2QYMQMGYST23ECQDIQACYMHYFIYNZMDW6QAAARI 2BF6MUQEYTGQQJUPRSJZIF7O6NYGCM3RG465H2UOKF6OEQX6BGS55OD23CFVZBNFT6O 25L2TUF2PVJ3CXAEF63FRRFAVDCRBUYVUW24RRJA2MI5WZOIYVCBBSBABLARO2AMR7N YWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4

We are decoding a QR code and receive an unexpected (incorrect) answer from the Delphi library. the Nodejs is the expected response.

Delphi result at map position 192 text converted to Ascii 101,110,86,84,108,118,79,82,70,53,102,111,82,68,103,99,57,70,89,120,84,67,53,77,54,48,118,55,102,110,88,83,113,116, 116,75,99,52,117,78,84,55,53,101,51,118,115,82,95,104,85,48,75,65,101,119,116,95,107,50,108,74,102,45,84,81,122,65,122,121,109,105,50,101,107,90,85,67,49,118,116,80,108,70,87,103,77

Nodejs result and the expected answer at map position 192 122, 117, 83, 150, 243, 145, 23, 151, 232, 68, 56, 28, 244, 86, 49, 76, 46, 76, 235, 75, 251, 126, 117, 210, 170, 219, 74, 115, 139, 141, 79, 190, 94,222, 251, 17, 254, 21, 52, 40, 7, 176, 183, 249, 54, 148, 151, 254, 77, 12, 192, 207, 41, 162, 217,233, 25, 80, 45, 111, 180, 249, 69, 90, 3

Decoding this QR string to a map need the result at 192 3ECQDIYBQEIRQ5MBDBXBQ7FIAGBRCFQUDBYIEA2Q2C5A4FSECFA4PKHNWFC5NRLIMIMHF JIYOQMJMGFWDJRDW3F2DC7BRRAYYBMEC6TVKOLPHEIXS7UEIOA46RLDCTBOJTVUX636 OXJKVW2KOOFY2T56L3PPWEP6CU2CQB5QW74TNFEX7ZGQZQGPFGRNT2IZKAWW7NHZIVN AGGGCQMMQIAKYELWQDEP3OFVEUZQ6YX5WINVT6YRF5P6BBJ7NUYGSWS5V435T5T53CI D7LARO2AMR7NYWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4MHLAQYN QMIEGE6UIMIUWCXPLMQKANEAAKRQ2QYMQMGYST23ECQDIQACYMHYFIYNZMDW6QAAARI 2BF6MUQEYTGQQJUPRSJZIF7O6NYGCM3RG465H2UOKF6OEQX6BGS55OD23CFVZBNFT6O 25L2TUF2PVJ3CXAEF63FRRFAVDCRBUYVUW24RRJA2MI5WZOIYVCBBSBABLARO2AMR7N YWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4

can someone help on this?

Here is Delphi Code:

s:= '3ECQDIYBQEIRQ5MBDBXBQ7FIAGBRCFQUDBYIEA2Q2C5A4FSECFA4PKHNWFC5NRLIMIMHF';
s:= s+'JIYOQMJMGFWDJRDW3F2DC7BRRAYYBMEC6TVKOLPHEIXS7UEIOA46RLDCTBOJTVUX636';
s:= s+'OXJKVW2KOOFY2T56L3PPWEP6CU2CQB5QW74TNFEX7ZGQZQGPFGRNT2IZKAWW7NHZIVN';
s:= s+'AGGGCQMMQIAKYELWQDEP3OFVEUZQ6YX5WINVT6YRF5P6BBJ7NUYGSWS5V435T5T53CI';
s:= s+'D7LARO2AMR7NYWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4MHLAQYN';
s:= s+'QMIEGE6UIMIUWCXPLMQKANEAAKRQ2QYMQMGYST23ECQDIQACYMHYFIYNZMDW6QAAARI';
s:= s+'2BF6MUQEYTGQQJUPRSJZIF7O6NYGCM3RG465H2UOKF6OEQX6BGS55OD23CFVZBNFT6O';
s:= s+'25L2TUF2PVJ3CXAEF63FRRFAVDCRBUYVUW24RRJA2MI5WZOIYVCBBSBABLARO2AMR7N';
s:= s+'YWUSTGD3C7WZBWWP3CEXV7YEFH5WTA2K2LWXTPWPWPXMJAP4';

//Decode Base32
bytes := TBase32.Rfc4648.Decode( s );
//remove the first three bytes and store in the resulting arry cborBytes2 := copy(bytes,3);

//get Cbor Map
items := TCborDecoding.DecodeData( @cborBytes2[0],Length(cborBytes2) );
memLog.Lines.Add('Found type ' + intToStr(Integer(items.CBorType)));

case items.cborType of
majMap: MemLog.Lines.Add('Map: Length: ' + IntToStr( (items as TCborMap).Count) + ': ' + items.ToString);
majUnsignedInt: MemLog.Lines.Add('UINt: ' + items.ToString );
majNegInt: MemLog.Lines.Add('negINt: ' + items.ToString );
majByteStr: rawData := items.ToString;
majUTFEncStr: MemLog.Lines.Add('UTF8: ' + items.ToString);
majArray: MemLog.Lines.Add('ARR: Length: ' + IntToStr( (items as TCborArr).Count ) + ': ' + items.ToString);
majTag: MemLog.Lines.Add('Tag - not implemented');
majFloat: MemLog.Lines.Add('Float: ' + items.ToString );
end;

itemsMap := ((items as TCborMap).ValueByName['124']) as TCborMap;
bytesAsStr := (itemsMap.ValueByName['114'] as TCborMap).ValueByName['192'].ToString;

memo1.Lines.Add(bytesAsStr);

Here is the node.js code

base32EncodedCredential = '3ECQDIYACEMHIGDODB6KQAMDCELBIGDQQIBVAGEOQRICNHQR5O2ULU3JFTZVHGAYOKSRQ5AYSYMLMGTBB36NUGF6DDCBRQCYIF5LYJB7VTXLGIZHZ6FP5B7X556XIOMDYWEO6PIGYWPRJEKPB2QJNWBW637IEAWAP544RL7Q6ZSNE5WTP4LQ523UFZBFGNH5BASK6JXGBQMMFAYZAQAVQIXNAFMX2WWF3ZONWCHPZQUYKDPQ2P6JGUMQXBXKXPVV5MDIQTNWUOXOYWBC5UAVS7K2YXPFZWYI57GCTBIN6DJ7ZE2RSC4G5K56WXVQNCCNW2R253AYOWBBQ3AYQIMJ5IQYRJMFG6WZAUA2IAIVBECAOST23ECQDIQBCYCRQQIILA5XUAAAVPLEEDLCRRJSC5XPBXLSBX3UQJELQCGUXFBFZD2FVNCLKAU75LFCPDKPZUWURTPWC762YD4ZNALVP7EN45FP3JJOEQMJIFIYUINGBVHE64MKIGTALONPOGFIQIMQIAKYELWQCWL5LLC54XG3BDX4YKMFBXYNH7ETKGILQ3VLX226WBUIJW3KHLXM';

const cbor = require('cbor'); const base32Decode = require('base32-decode')

const cborArrayBuffer = base32Decode(base32EncodedCredential, 'RFC4648');

const cborBytes = new Uint8Array(cborArrayBuffer.slice(3));

console.log(cborBytes);

const cborMap = cbor.decode(cborBytes,{useMaps:true});

const vcMap = cborMap.get(124);

console.log(vcMap.get(114).get(192));

const proofValue = convertToMultibase(vcMap.get(114).get(192));

//any help on this issue would be appreciated Ray Huff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.