Permalink
Browse files

[enhance] binary: buffer_of_binary always trims contents first

  • Loading branch information...
1 parent 12cd27a commit ec3ba5004a81d8fe99280d465f645e1ce0422565 @Aqua-Ye Aqua-Ye committed Dec 5, 2012
Showing with 3 additions and 7 deletions.
  1. +2 −7 lib/plugins/crypto/bslCrypto.nodejs
  2. +1 −0 lib/plugins/opabsl/jsbsl/bslBinary.js
@@ -44,7 +44,6 @@ function md5(data) {
* @register {binary -> string}
*/
function base64_encode(data) {
- BslBinary_trim(data);
return buffer_of_binary(data).toString('base64');
}
@@ -61,7 +60,6 @@ function base64_decode(data) {
* @register {binary -> string}
*/
function base64_encode_compact(bin) {
- BslBinary_trim(bin);
// compact just means no lines and no padding
var data = buffer_of_binary(bin).toString('base64');
return data.substr(0,Math.ceil((str.length * 4) / 3));
@@ -71,7 +69,6 @@ function base64_encode_compact(bin) {
* @register {binary -> string}
*/
function base64_encode_multiline(bin) {
- BslBinary_trim(bin);
// This faithfully follows the strange pattern of carriage returns
// generated by Cryptokit.
var width = 72;
@@ -102,9 +99,8 @@ function base64_decode2(data) {
* @register {string, binary -> binary}
*/
function hash_digest(algo, bin) {
- BslBinary_trim(bin);
return binary_of_buffer(
- new Buffer(Crypto.createHash(algo).update(bin.contents).digest('binary'),
+ new Buffer(Crypto.createHash(algo).update(buffer_of_binary(bin)).digest('binary'),
'binary')
);
}
@@ -113,9 +109,8 @@ function hash_digest(algo, bin) {
* @register {string, binary, binary -> binary}
*/
function hmac_digest(algo, key, bin) {
- BslBinary_trim(key); BslBinary_trim(bin);
return binary_of_buffer(
- new Buffer(Crypto.createHmac(algo, key.contents).update(bin.contents).digest('binary'),
+ new Buffer(Crypto.createHmac(algo, buffer_of_binary(key)).update(buffer_of_binary(bin)).digest('binary'),
'binary')
);
}
@@ -32,6 +32,7 @@ function binary_of_buffer(contents){
}
function buffer_of_binary(bin){
+ trim(bin);
return bin.contents;
}

0 comments on commit ec3ba50

Please sign in to comment.