Permalink
Browse files

[enhance] bslCrypto: removed decode2 function, factorize, doc

  • Loading branch information...
1 parent c30a443 commit 6349cc51c6dc4efb063c8a7a876f1a97323d77ef @Aqua-Ye Aqua-Ye committed Dec 7, 2012
Showing with 11 additions and 21 deletions.
  1. +11 −21 lib/plugins/crypto/bslCrypto.nodejs
View
32 lib/plugins/crypto/bslCrypto.nodejs
@@ -39,33 +39,23 @@ function md5(data) {
/**
* Encode a binary string as Base 64
*
- * @param {!binary} str A text of arbitrary length.
+ * @param {!binary} bin A binary of arbitrary length.
* @return {!string} A (longer) representation, encoded as base 64
* @register {binary -> string}
*/
-function base64_encode(data) {
- return buffer_of_binary(data).toString('base64');
-}
-
-/**
- * @param {!string} str A base64-encoded text
- * @return {!binary} A decoded representation
- * @register {string -> binary}
- */
-function base64_decode(data) {
- return binary_of_buffer(new Buffer(data, 'base64'));
+function base64_encode(bin) {
+ return buffer_of_binary(bin).toString('base64');
}
/**
* @register {binary -> string}
*/
function base64_encode_compact(bin) {
// compact just means no lines and no padding
- var data = buffer_of_binary(bin).toString('base64');
+ var data = base64_encode(bin);
data = data.replace('\n', '');
- var len = data.length;
- if (data[len-1] == '=') {
- if (data[len-2] == '=') return data.slice(0,-2);
+ if (data[data.length-1] == '=') {
+ if (data[data.length-2] == '=') return data.slice(0,-2);
else return data.slice(0,-1);
}
return data;
@@ -78,7 +68,7 @@ function base64_encode_multiline(bin) {
// This faithfully follows the strange pattern of carriage returns
// generated by Cryptokit.
var width = 72;
- var data = buffer_of_binary(bin).toString('base64');
+ var data = base64_encode(bin);
if (data.length < 4) return data;
if (data.length < width) return data+'\n';
var strs = [];
@@ -93,12 +83,12 @@ function base64_encode_multiline(bin) {
}
/**
+ * @param {!string} str A base64-encoded text
+ * @return {!binary} A decoded representation
* @register {string -> binary}
*/
-function base64_decode2(data) {
- // I've no idea what the difference is between decode and decode2
- // One uses Caml code in libbase, the other uses Cryptokit.
- return binary_of_buffer(new Buffer(data, 'base64'));
+function base64_decode(data) {
+ return binary_of_buffer(new Buffer(data, 'base64'));
}
/**

0 comments on commit 6349cc5

Please sign in to comment.