Skip to content

Commit bbdf82a

Browse files
committed
Merge pull request #32 from coolaj86/patch-4
lint fix: move functions above usage
2 parents 7affcb5 + e9d003f commit bbdf82a

1 file changed

Lines changed: 29 additions & 30 deletions

File tree

index.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,35 @@
22

33
var crypto = require('crypto');
44

5+
/**
6+
* convert an integer to a byte array
7+
* @param {Integer} num
8+
* @return {Array} bytes
9+
*/
10+
function intToBytes(num) {
11+
var bytes = [];
12+
13+
for(var i=7 ; i>=0 ; --i) {
14+
bytes[i] = num & (255);
15+
num = num >> 8;
16+
}
17+
18+
return bytes;
19+
}
20+
21+
/**
22+
* convert a hex value to a byte array
23+
* @param {String} hex string of hex to convert to a byte array
24+
* @return {Array} bytes
25+
*/
26+
function hexToBytes(hex) {
27+
var bytes = [];
28+
for(var c = 0, C = hex.length; c < C; c += 2) {
29+
bytes.push(parseInt(hex.substr(c, 2), 16));
30+
}
31+
return bytes;
32+
}
33+
534
var hotp = {};
635

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

191220
module.exports.hotp = hotp;
192221
module.exports.totp = totp;
193-
194-
/**
195-
* convert an integer to a byte array
196-
* @param {Integer} num
197-
* @return {Array} bytes
198-
*/
199-
var intToBytes = function(num) {
200-
var bytes = [];
201-
202-
for(var i=7 ; i>=0 ; --i) {
203-
bytes[i] = num & (255);
204-
num = num >> 8;
205-
}
206-
207-
return bytes;
208-
};
209-
210-
211-
/**
212-
* convert a hex value to a byte array
213-
* @param {String} hex string of hex to convert to a byte array
214-
* @return {Array} bytes
215-
*/
216-
var hexToBytes = function(hex) {
217-
var bytes = [];
218-
for(var c = 0, C = hex.length; c < C; c += 2) {
219-
bytes.push(parseInt(hex.substr(c, 2), 16));
220-
}
221-
return bytes;
222-
};

0 commit comments

Comments
 (0)