Last active
January 1, 2016 20:19
-
-
Save vukicevic/8196318 to your computer and use it in GitHub Desktop.
ASN.1 BER length generator. Pass a length l to the function, outputs an array with a BER format length. JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function berLength(l) { | |
var ll, bl; | |
if (l < 128) { | |
bl = [l]; | |
} else { | |
ll = Math.floor(Math.log(l)/Math.log(256))+1; | |
bl = [128 + ll]; | |
while (ll-- > 0) | |
bl.push( (l >> (ll*8)) & 255 ); | |
} | |
return bl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment