Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arrayBufferToInt = function(buffer) {
- return new Int16Array(buffer)[0];
- }
- var parceTLV = function(assertion) {
- let buffer = Base64URLToArrayBuffer(assertion);
- let tlv = parceTLVRec(buffer);
- return tlv;
- }
- var parceTLVRec = function(buffer) {
- let tlv = {};
- if(arrayBufferToInt(buffer.slice(0,2)) >> 8 !== 0x3E
- && arrayBufferToInt(buffer.slice(0,2)) >> 8 !== 0x2E)
- return ArrayBufferToBase64URL(buffer);
- while(buffer.byteLength > 0) {
- let tag = arrayBufferToInt(buffer.slice(0,2));
- let tag_string = PREDEFINED_TAGS[tag];
- let len = arrayBufferToInt(buffer.slice(2,4));
- tlv[tag_string] = parceTLVRec(buffer.slice(4, len));
- buffer = buffer.slice(len + 4, buffer.byteLength);
- }
- return tlv
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement