Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
27 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}; |