Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
adding stronglyBound option for Secure, adding Secure.reset to nuke a…
…ll data
  • Loading branch information
kassens committed Oct 20, 2008
1 parent 18bae8c commit 512de73
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
9 changes: 3 additions & 6 deletions Source/Data/Hash.Secure.js
Expand Up @@ -2,22 +2,19 @@ Hash.Secure = new Class({

Extends: Secure,

Implements: Options,

options: {
autoSave: true
},

initialize: function(name, options){
this.parent(name);
this.setOptions(options);
initialize: function(key, options){
this.parent(key, options);
this.load();
},

save: function(){
var value = JSON.encode(this.hash);
if (!value) return false;
if (value == '{}') air.EncryptedLocalStore.removeItem(this.name);
if (value == '{}') this.dispose();
else this.write(value);
return true;
},
Expand Down
37 changes: 24 additions & 13 deletions Source/Data/Secure.js
@@ -1,37 +1,48 @@
var Secure = new Class({

initialize: function(key){
this.key = key;
Implements: Options,

options: {
stronglyBound: false
},

write: function(value){
Secure.write(this.key, value);
return this;
initialize: function(key, options){
this.setOptions(options);
this.key = key;
},

read: function(){
return Secure.read(this.key);
},

write: function(value){
Secure.write(this.key, value, this.options.stronglyBound);
return this;
},

dispose: function(){
Secure.dispose(this.key);
return this;
}

});

Secure.write = function(key, value){
Secure.read = function(key){
var bytes = air.EncryptedLocalStore.getItem(key);
return (bytes === null) ? null : bytes.readUTFBytes(bytes.length);
};

Secure.write = function(key, value, stronglyBound){
var bytes = new air.ByteArray();
bytes.writeUTFBytes(value);
air.EncryptedLocalStore.setItem(this.key, bytes);
air.EncryptedLocalStore.setItem(key, bytes, stronglyBound);
};

// TODO: should return null, if key not found
Secure.read = function(key){
var storedValue = air.EncryptedLocalStore.getItem(this.key);
return storedValue.readUTFBytes(storedValue.length);
Secure.dispose = function(key){
air.EncryptedLocalStore.removeItem(key);
};

Secure.dispose = function(key){
air.EncryptedLocalStore.removeItem(this.key);
// Clears the entire encrypted local store, deleting all data.
Secure.reset = function(){
air.EncryptedLocalStore.reset();
};

0 comments on commit 512de73

Please sign in to comment.