Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
added setEncryptionAdapter to enable upstream crypto (#21)
Browse files Browse the repository at this point in the history
* added setEncryptionAdapter to enable upstream crypto

* added missing semicolon

* added missing parenthesis

* renamed function to override hashing method

* added missing semicolon

* fixed typo

* fixed typo

* corrected definitions

* exported function

* fixed typo on definitions
  • Loading branch information
emilioicai authored and wtrocki committed Jun 15, 2017
1 parent ff064f8 commit 764b00b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions fh-sync-js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ declare module SyncClient {
* @param handler - function that wraps underlying storage solution
*/
function setStorageAdapter(handler: (dataset_id:string, isSave: boolean, cb: any) => void);

/**
* Allows to override default hashing method
*
* @param handler - function that wraps underlying hashing method
*/
function setHashMethod(method: () => any);
}

export = SyncClient;
12 changes: 10 additions & 2 deletions src/sync-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ var self = {
},

generateHash: function(object) {
var hash = CryptoJS.SHA1(self.sortedStringify(object));
var hash = self.getHashMethod(self.sortedStringify(object));
return hash.toString();
},

Expand Down Expand Up @@ -908,6 +908,11 @@ var self = {
setStorageAdapter: function(adapter){
self.getStorageAdapter = adapter;
},

/** Allow to set custom hasing method **/
setHashMethod: function(method){
self.getHashMethod = method;
},

getStorageAdapter: function(dataset_id, isSave, cb){
var onFail = function(msg, err){
Expand All @@ -920,6 +925,8 @@ var self = {
});
},

getHashMethod: CryptoJS.SHA1,

saveDataSet: function (dataset_id, cb) {
self.getDataSet(dataset_id, function(dataset) {
self.getStorageAdapter(dataset_id, true, function(err, storage){
Expand Down Expand Up @@ -1260,5 +1267,6 @@ module.exports = {
clearCache: self.clearCache,
setCloudHandler: self.setCloudHandler,
doCloudCall: self.doCloudCall,
setStorageAdapter: self.setStorageAdapter
setStorageAdapter: self.setStorageAdapter,
setHashMethod: self.setHashMethod
};

0 comments on commit 764b00b

Please sign in to comment.