* byte tells the type of entry.
*/
- static Entry decode(Slot slot, ByteBuffer bb) {
+ slottatic Entry decode(Slot slot, ByteBuffer bb) {
byte type=bb.get();
switch(type) {
case TypeKeyValue:
/** Sequence number of the slot. */
private long seqnum;//
/** HMAC of previous slot. */
- private byte[] prevhmac;
+ private byte[] prevhmac;//
/** HMAC of this slot. */
- private byte[] hmac;
+ private byte[] hmac;//
/** Machine that sent this slot. */
- private long machineid;
+ private long machineid;//
/** Vector of entries in this slot. */
private Vector<Entry> entries;
/** Pieces of information that are live. */
- private int livecount;
+ private int livecount;//
/** Flag that indicates whether this slot is still live for
* recording the machine that sent it. */
- private boolean seqnumlive;
+ private boolean seqnumlive;//
/** Number of bytes of free space. */
private int freespace;
}
Slot(long _seqnum, long _machineid) {
- this(_seqnum, _machineid, new byte[HMAC_SIZE], null);
+ this(_seqnum, _machineid, new byte[ HMAC_SIZE], null);
}
byte[] getHMAC() {
-class Slot{
- constructor(seqnum,machineid,prevhmac,hmac){
- this.SLOT_SIZE=2048;
- this.RESERVED_SPACE=64;
- this.HMAC_SIZE=32;
- (typeof seqnum === "number")? this.seqnum = seqnum : throw new Error("seqnum should be a number");
- (typeof machineid === "number")? this.machineid = seqnum : throw new Error("seqnum should be a number");
-
+class Slot {
+ constructor(seqnum, machineid, prevhmac, hmac) {
+ this.SLOT_SIZE = 2048;
+ this.RESERVED_SPACE = 64;
+ this.HMAC_SIZE = 32;
+ (typeof seqnum === "number") ? this.seqnum = seqnum: throw new Error("seqnum should be a number");
+ (typeof machineid === "number") ? this.machineid = seqnum: throw new Error("machine should be a number");
+ this.livecount = 1;
+ this.seqnumlive = true;
+ (prevhmac && prevhmac instanceof Uint8Array) ? this.prevhmac = prevhmac: this.prevhmac = new Uint8Array(this.HMAC_SIZE));
+ (hmac && hmac instanceof Uint8Array) ? this.hmac = hmac: this.hmac = null;
+ this.entries = [];
+ this.freespace = this.SLOT_SIZE - getBaseSize(); //???????
+ }
+ getHMAC() {
+ return this.hmac;
+ }
+ getPrevHmac() {
+ return this.prevhmac;
+ }
+ addEntry(entry) {
+ if (entry && entry instanceof Entry) {
+ var obj;
+ this.entries.push(_.extend(obj, entry));
+ this.livecount++;
+ freespace -= entry.getSize();
+ }
+ }
+ addShallowEntry(entry){
+ if(entry && entry instanceof Entry){
+ this.entries.push(entry);
+ this.livecount++;
+ freespace -= entry.getSize();
+ }
+ }
+ hasSpace(entry){
+ var newfreespace = this.freespace - entry.getSize();
+ return newfreespace > this.RESERVED_SPACE;
+ }
+ canFit(entry){
+ var newfreespace = this.freespace - entry.getSize();
+ return newfreespace >= 0;
+ }
+ getEntries(){
+ return this.entries;
+ }
+ static decode(array){
+ var cond1 = (array && array instanceof Uint8Array);
+ if(cond1){
+ }
}
}
\ No newline at end of file
"gulp-uglify": "1.1.0",
"jshint-stylish": "1.0.1",
"minimist": "1.1.1",
+ "node-forge": "^0.6.41",
"object-hash": "^1.1.3",
"request": "^2.74.0",
"underscore": "^1.8.3"
/* jshint devel:true */
"use strict";
-console.log('Welcome to iotjs-www','\n\n');
-
+console.log('Welcome to iotjs-www', '\n\n');
// set up the base line..
// Using browserify to set up browser exports
var crypto = require('crypto-js');
-var hash = require('object-hash');
var _ = require('underscore');
-var ByteBuffer = require("bytebuffer");
-
-
+var ByteBuffer = require('bytebuffer');
+var hash = require('object-hash');
+var forge = require('node-forge');
(function() {
-
var root = this;
-
-
// iot namespace main constructor
var iot = function(obj) {
if (obj instanceof iot) return obj;
if (!(this instanceof iot)) return new iot(obj);
this.iot = obj;
};
-
// export iot to the global exports
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
root.iot = iot;
}
- iot.baselinetest = function(){
- // baseline test
+
+ iot.baselinetest = function() {
+ // baseline test
console.log('its alive!!!');
console.log();
+
//local hash test
console.log(hash('hello man'));
console.log(typeof hash('hello man'));
console.log();
+
//Pair test
- var p = new Pair(1,2);
+ var p = new Pair(1, 2);
console.log(p.toString());
console.log();
+
//iotstring test
var i = new IoTString('hello');
console.log(i.length());
console.log();
- }
-
-
-
-
-
-
-
-
-
+ //local crypto test
+ var data = [{id: 1}, {id: 2}];
+ // Encrypt
+ var ciphertext = crypto.AES.encrypt(JSON.stringify(data), 'secret key 123');
+ // Decrypt
+ var bytes = crypto.AES.decrypt(ciphertext.toString(), 'secret key 123');
+ var decryptedData = JSON.parse(bytes.toString(crypto.enc.Utf8));
+ // console.log(decryptedData);
+ var e = crypto.HmacMD5("Mess", "Secret Passphrase");
+ console.log(typeof e.toString());
+ }
}())
\ No newline at end of file