Tidy up generateKey

This commit is contained in:
Raymond Feng 2014-05-15 10:49:38 -07:00
parent dbe3a11a27
commit 002e515ecf
2 changed files with 3 additions and 13 deletions

View File

@ -1,5 +1,6 @@
var loopback = require('../loopback');
var assert = require('assert');
var generateKey = require('./utils').generateKey;
// Authentication schemes
var AuthenticationSchemeSchema = {
@ -94,18 +95,6 @@ var ApplicationSchema = {
* Application management functions
*/
var crypto = require('crypto');
function generateKey(hmacKey, algorithm, encoding) {
hmacKey = hmacKey || 'loopback';
algorithm = algorithm || 'sha1';
encoding = encoding || 'hex';
var hmac = crypto.createHmac(algorithm, hmacKey);
var buf = crypto.randomBytes(32);
hmac.update(buf);
var key = hmac.digest(encoding);
return key;
}
/**
* Manage client applications and organize their users.

View File

@ -2,6 +2,7 @@
* Internal utilities for models
*/
var crypto = require('crypto');
var assert = require('assert');
/**
* Get the model class
@ -24,7 +25,7 @@ function getModel(cls, base) {
* @returns {String} The generated key
*/
function generateKey(hmacKey, algorithm, encoding) {
hmacKey = hmacKey || 'loopback';
assert(hmacKey, 'HMAC key is required');
algorithm = algorithm || 'sha1';
encoding = encoding || 'hex';
var hmac = crypto.createHmac(algorithm, hmacKey);