From 38c9dc199294dce6d51a0b225d0455f6578e239c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 26 Apr 2017 18:46:54 +0200 Subject: [PATCH 1/2] feat/Immutable XorName is now represented as an Array Previously we were leaking out ref-array objects here, but that caused troubles when they were used at other parts of the API. Namely if they were serialised without being converted. In order to make things easier we are now always copying them into a JS Array before returning them in the API call and are copying back if they are given as such. --- src/native/_immutable.js | 12 +++++++++++- test/immutable.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/native/_immutable.js b/src/native/_immutable.js index 62b947e..7937584 100644 --- a/src/native/_immutable.js +++ b/src/native/_immutable.js @@ -18,6 +18,8 @@ function translateXorName(appPtr, str) { } else { name = str; } + } else if (Array.isArray(str)) { + name = t.XOR_NAME(str).ref().readPointer(0) } else { const b = new Buffer(str); if (b.length != 32) throw Error("XOR Names _must be_ 32 bytes long.") @@ -26,6 +28,14 @@ function translateXorName(appPtr, str) { return [appPtr, name] } +function copyFromRefArray(refArray){ + let target = []; + for (var i = 0; i < refArray.length; i++) { + target.push(refArray[i]) + } + return target; +} + module.exports = { types: { @@ -50,7 +60,7 @@ module.exports = { }, null), idata_close_self_encryptor: h.Promisified(null, 'pointer', // make a copy to ensure the data stays around - resp => t.XOR_NAME(ref.reinterpret(resp[0], 32))), + resp => copyFromRefArray(t.XOR_NAME(ref.reinterpret(resp[0], 32)))), idata_fetch_self_encryptor: h.Promisified(translateXorName, SEReadHandle), idata_size: h.Promisified(null, t.u64), idata_read_from_self_encryptor: h.Promisified(null, [t.u8Pointer, t.usize, t.usize], h.asBuffer), diff --git a/test/immutable.js b/test/immutable.js index 039bba3..9fdca85 100644 --- a/test/immutable.js +++ b/test/immutable.js @@ -18,7 +18,7 @@ describe('Immutable Data', () => { }))); }); - it.skip('store address in a MD', () => { + it('store address in a MD', () => { const testString = `test-${Math.random()}`; const testXorName = h.createRandomXorName(); From 18642a67d8928c822e003438d0f797eada57e86c Mon Sep 17 00:00:00 2001 From: Benjamin Kampmann Date: Wed, 26 Apr 2017 18:48:28 +0200 Subject: [PATCH 2/2] fix/NFS convert incoming array back to ref-array Internally we are using ref-array structs when dealing with data_map_names and since the latest change this has been a JS array instead. This checks for that when the (nfs) File Object is created and converts it into the proper ref-array type again. --- src/api/emulations/nfs.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/api/emulations/nfs.js b/src/api/emulations/nfs.js index 3d965a2..1019571 100644 --- a/src/api/emulations/nfs.js +++ b/src/api/emulations/nfs.js @@ -19,6 +19,10 @@ class File { **/ constructor(ref) { this._ref = ref; + if (Array.isArray(ref.data_map_name)) { + // translate the incoming array back into a buffer we can use internally + this._ref.data_map_name = t.XOR_NAME(ref.data_map_name); + } } get ref() { @@ -28,8 +32,8 @@ class File { modified_sec: this._ref.modified_sec, modified_nsec: this._ref.modified_nsec, size: this._ref.size, - data_map_name: this._ref.data_map_name, - user_metadata_ptr: this._ref.data_map_name.ref(), + data_map_name: this.dataMapName, + user_metadata_ptr: this.dataMapName.ref(), user_metadata_len: 0, user_metadata_cap: 0 }; @@ -156,7 +160,7 @@ class NFS { **/ update(fileName, file, version) { return lib.file_update(this.mData.app.connection, this.mData.ref, fileName, - file.ref.ref(), version) + file.ref.ref(), version) .then(() => file); } }