Skip to content

Commit

Permalink
Merge pull request #32 from coolaj86/patch-4
Browse files Browse the repository at this point in the history
lint fix: move functions above usage
  • Loading branch information
guyht committed Oct 8, 2015
2 parents 7affcb5 + e9d003f commit bbdf82a
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions index.js
Expand Up @@ -2,6 +2,35 @@

var crypto = require('crypto');

/**
* convert an integer to a byte array
* @param {Integer} num
* @return {Array} bytes
*/
function intToBytes(num) {
var bytes = [];

for(var i=7 ; i>=0 ; --i) {
bytes[i] = num & (255);
num = num >> 8;
}

return bytes;
}

/**
* convert a hex value to a byte array
* @param {String} hex string of hex to convert to a byte array
* @return {Array} bytes
*/
function hexToBytes(hex) {
var bytes = [];
for(var c = 0, C = hex.length; c < C; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
}

var hotp = {};

/**
Expand Down Expand Up @@ -190,33 +219,3 @@ totp.verify = function(token, key, opt) {

module.exports.hotp = hotp;
module.exports.totp = totp;

/**
* convert an integer to a byte array
* @param {Integer} num
* @return {Array} bytes
*/
var intToBytes = function(num) {
var bytes = [];

for(var i=7 ; i>=0 ; --i) {
bytes[i] = num & (255);
num = num >> 8;
}

return bytes;
};


/**
* convert a hex value to a byte array
* @param {String} hex string of hex to convert to a byte array
* @return {Array} bytes
*/
var hexToBytes = function(hex) {
var bytes = [];
for(var c = 0, C = hex.length; c < C; c += 2) {
bytes.push(parseInt(hex.substr(c, 2), 16));
}
return bytes;
};

0 comments on commit bbdf82a

Please sign in to comment.