Skip to content

Commit e40377a

Browse files
committed
Removes unused functions from convert
1 parent 69c0497 commit e40377a

File tree

2 files changed

+1
-100
lines changed

2 files changed

+1
-100
lines changed

src/convert.js

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var Crypto = require('crypto-js')
22
var WordArray = Crypto.lib.WordArray
3-
var base64map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
43

54
function lpad(str, padString, length) {
65
while (str.length < length) str = padString + str
@@ -24,78 +23,6 @@ function hexToBytes(hex) {
2423
})
2524
}
2625

27-
function bytesToBase64(bytes) {
28-
var base64 = []
29-
30-
for (var i = 0; i < bytes.length; i += 3) {
31-
var triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]
32-
33-
for (var j = 0; j < 4; j++) {
34-
if (i * 8 + j * 6 <= bytes.length * 8) {
35-
base64.push(base64map.charAt((triplet >>> 6 * (3 - j)) & 0x3F))
36-
} else {
37-
base64.push('=')
38-
}
39-
}
40-
}
41-
42-
return base64.join('')
43-
}
44-
45-
function base64ToBytes(base64) {
46-
// Remove non-base-64 characters
47-
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '')
48-
49-
var bytes = []
50-
var imod4 = 0
51-
52-
for (var i = 0; i < base64.length; imod4 = ++i % 4) {
53-
if (!imod4) continue
54-
55-
bytes.push(
56-
(
57-
(base64map.indexOf(base64.charAt(i - 1)) & (Math.pow(2, -2 * imod4 + 8) - 1)) <<
58-
(imod4 * 2)
59-
) |
60-
(base64map.indexOf(base64.charAt(i)) >>> (6 - imod4 * 2))
61-
)
62-
}
63-
64-
return bytes
65-
}
66-
67-
/**
68-
* Hex only (allowing bin would be potentially risky, as 01010101 = \x01 * 4 or 85)
69-
*/
70-
function coerceToBytes(input) {
71-
if (typeof input != 'string') return input
72-
return hexToBytes(input)
73-
}
74-
75-
function binToBytes(bin) {
76-
return bin.match(/......../g).map(function(x) {
77-
return parseInt(x,2)
78-
})
79-
}
80-
81-
function bytesToBin(bytes) {
82-
return bytes.map(function(x) {
83-
return lpad(x.toString(2), '0', 8)
84-
}).join('')
85-
}
86-
87-
function bytesToString(bytes) {
88-
return bytes.map(function(x){
89-
return String.fromCharCode(x)
90-
}).join('')
91-
}
92-
93-
function stringToBytes(string) {
94-
return string.split('').map(function(x) {
95-
return x.charCodeAt(0)
96-
})
97-
}
98-
9926
/**
10027
* Create a byte array representing a number with the given length
10128
*/
@@ -181,13 +108,6 @@ module.exports = {
181108
lpad: lpad,
182109
bytesToHex: bytesToHex,
183110
hexToBytes: hexToBytes,
184-
bytesToBase64: bytesToBase64,
185-
base64ToBytes: base64ToBytes,
186-
coerceToBytes: coerceToBytes,
187-
binToBytes: binToBytes,
188-
bytesToBin: bytesToBin,
189-
bytesToString: bytesToString,
190-
stringToBytes: stringToBytes,
191111
numToBytes: numToBytes,
192112
bytesToNum: bytesToNum,
193113
numToVarInt: numToVarInt,

test/convert.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var assert = require('assert')
2-
var convert = require('../src/convert.js')
2+
var convert = require('../').convert
33

44
describe('convert', function() {
55
describe('bytesToHex', function() {
@@ -25,25 +25,6 @@ describe('convert', function() {
2525
assert.deepEqual(convert.hexToBytes(hex), bytes)
2626
})
2727

28-
describe('bytesToBase64', function() {
29-
it('passes RFC4648 test vectors', function() {
30-
// Test vectors from:
31-
// http://tools.ietf.org/html/rfc4648#page-12
32-
33-
var b64 = function(s) {
34-
return convert.bytesToBase64(convert.stringToBytes(s))
35-
}
36-
37-
assert.equal(b64(''), '')
38-
assert.equal(b64('f'), 'Zg==')
39-
assert.equal(b64('fo'), 'Zm8=')
40-
assert.equal(b64('foo'), 'Zm9v')
41-
assert.equal(b64('foob'), 'Zm9vYg==')
42-
assert.equal(b64('fooba'), 'Zm9vYmE=')
43-
assert.equal(b64('foobar'), 'Zm9vYmFy')
44-
})
45-
})
46-
4728
describe('byte array and word array conversions', function(){
4829
var bytes, wordArray
4930

0 commit comments

Comments
 (0)