Skip to content

Commit

Permalink
release new version 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
nitram509 committed Jun 5, 2016
1 parent 560afd1 commit 249ac4b
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 148 deletions.
2 changes: 1 addition & 1 deletion lib/Base64Tools.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
export = Base64Tools;
declare class Base64Tools {
private static BASE64_PADDING;
Expand Down
2 changes: 1 addition & 1 deletion lib/BufferTools.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
export = BufferTools;
declare class BufferTools {
static equals(a: Buffer, b: Buffer): boolean;
Expand Down
4 changes: 3 additions & 1 deletion lib/CaveatPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ var CaveatPacket = (function () {
};
CaveatPacket.prototype.getValueAsText = function () {
if (this.valueAsText == null) {
this.valueAsText = (this.type == 4 /* vid */) ? Base64Tools.encodeBase64UrlSafe(this.rawValue.toString('base64')) : this.rawValue.toString(MacaroonsContants.IDENTIFIER_CHARSET);
this.valueAsText = (this.type == CaveatPacketType.vid)
? Base64Tools.encodeBase64UrlSafe(this.rawValue.toString('base64'))
: this.rawValue.toString(MacaroonsContants.IDENTIFIER_CHARSET);
}
return this.valueAsText;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/CryptoTools.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
import ThirdPartyPacket = require('./ThirdPartyPacket');
export = CryptoTools;
declare class CryptoTools {
Expand Down
5 changes: 4 additions & 1 deletion lib/Macaroon.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ var Macaroon = (function () {
return MacaroonsSerializer.serialize(this);
};
Macaroon.prototype.inspect = function () {
return this.createKeyValuePacket(0 /* location */, this.location) + this.createKeyValuePacket(1 /* identifier */, this.identifier) + this.createCaveatsPackets(this.caveatPackets) + this.createKeyValuePacket(2 /* signature */, this.signature);
return this.createKeyValuePacket(CaveatPacketType.location, this.location)
+ this.createKeyValuePacket(CaveatPacketType.identifier, this.identifier)
+ this.createCaveatsPackets(this.caveatPackets)
+ this.createKeyValuePacket(CaveatPacketType.signature, this.signature);
};
Macaroon.prototype.createKeyValuePacket = function (type, value) {
return value != null ? CaveatPacketType[type] + MacaroonsContants.KEY_VALUE_SEPARATOR_STR + value + MacaroonsContants.LINE_SEPARATOR_STR : "";
Expand Down
2 changes: 1 addition & 1 deletion lib/MacaroonsBuilder.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
import Macaroon = require('./Macaroon');
export = MacaroonsBuilder;
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/MacaroonsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var MacaroonsBuilder = (function () {
throw new Error("Too many caveats. There are max. " + MacaroonsConstants.MACAROON_MAX_CAVEATS + " caveats allowed.");
}
var signature = CryptoTools.macaroon_hmac(this.macaroon.signatureBuffer, caveatBuffer);
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(3 /* cid */, caveatBuffer));
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(CaveatPacketType.cid, caveatBuffer));
this.macaroon = new Macaroon(this.macaroon.location, this.macaroon.identifier, signature, caveatsExtended);
}
return this;
Expand All @@ -93,7 +93,7 @@ var MacaroonsBuilder = (function () {
}
var thirdPartyPacket = CryptoTools.macaroon_add_third_party_caveat_raw(this.macaroon.signatureBuffer, secret, identifier);
var hash = thirdPartyPacket.signature;
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(3 /* cid */, identifier), new CaveatPacket(4 /* vid */, thirdPartyPacket.vid_data), new CaveatPacket(5 /* cl */, location));
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(CaveatPacketType.cid, identifier), new CaveatPacket(CaveatPacketType.vid, thirdPartyPacket.vid_data), new CaveatPacket(CaveatPacketType.cl, location));
this.macaroon = new Macaroon(this.macaroon.location, this.macaroon.identifier, hash, caveatsExtended);
return this;
};
Expand Down
148 changes: 15 additions & 133 deletions lib/MacaroonsDeSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ var MacaroonsDeSerializer = (function () {
}
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.CID_BYTES)) {
s = MacaroonsDeSerializer.parsePacket(packet, MacaroonsConstants.CID_BYTES);
caveats.push(new CaveatPacket(3 /* cid */, s));
caveats.push(new CaveatPacket(CaveatPacketType.cid, s));
}
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.CL_BYTES)) {
s = MacaroonsDeSerializer.parsePacket(packet, MacaroonsConstants.CL_BYTES);
caveats.push(new CaveatPacket(5 /* cl */, s));
caveats.push(new CaveatPacket(CaveatPacketType.cl, s));
}
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.VID_BYTES)) {
raw = MacaroonsDeSerializer.parseRawPacket(packet, MacaroonsConstants.VID_BYTES);
caveats.push(new CaveatPacket(4 /* vid */, raw));
caveats.push(new CaveatPacket(CaveatPacketType.vid, raw));
}
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.SIGNATURE_BYTES)) {
signature = MacaroonsDeSerializer.parseSignature(packet, MacaroonsConstants.SIGNATURE_BYTES);
Expand Down Expand Up @@ -132,7 +132,10 @@ var StatefulPacketReader = (function () {
return -1;
};
StatefulPacketReader.prototype.readPacketHeader = function () {
return (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 12) | (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 8) | (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 4) | StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]];
return (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 12)
| (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 8)
| (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 4)
| StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]];
};
StatefulPacketReader.prototype.isPacketHeaderAvailable = function () {
return this.seekIndex <= (this.buffer.length - MacaroonsConstants.PACKET_PREFIX_LENGTH);
Expand All @@ -141,135 +144,14 @@ var StatefulPacketReader = (function () {
return !(this.seekIndex < this.buffer.length);
};
StatefulPacketReader.HEX_ALPHABET = [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
0,
0,
0,
0,
0,
0,
0,
10,
11,
12,
13,
14,
15,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
10,
11,
12,
13,
14,
15,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
];
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
return StatefulPacketReader;
})();
module.exports = MacaroonsDeSerializer;
2 changes: 1 addition & 1 deletion lib/MacaroonsSerializer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
import Macaroon = require('./Macaroon');
export = MacaroonsSerializer;
declare class MacaroonsSerializer {
Expand Down
4 changes: 2 additions & 2 deletions lib/MacaroonsSerializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ var MacaroonsSerializer = (function () {
}
MacaroonsSerializer.serialize = function (macaroon) {
var packets = [];
packets.push(MacaroonsSerializer.serialize_packet(0 /* location */, macaroon.location), MacaroonsSerializer.serialize_packet(1 /* identifier */, macaroon.identifier));
packets.push(MacaroonsSerializer.serialize_packet(CaveatPacketType.location, macaroon.location), MacaroonsSerializer.serialize_packet(CaveatPacketType.identifier, macaroon.identifier));
packets = packets.concat(macaroon.caveatPackets.map(function (caveatPacket) {
return MacaroonsSerializer.serialize_packet_buf(caveatPacket.type, caveatPacket.rawValue);
}));
packets.push(MacaroonsSerializer.serialize_packet_buf(2 /* signature */, macaroon.signatureBuffer));
packets.push(MacaroonsSerializer.serialize_packet_buf(CaveatPacketType.signature, macaroon.signatureBuffer));
var base64 = MacaroonsSerializer.flattenByteArray(packets).toString("base64");
return Base64Tools.encodeBase64UrlSafe(base64);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/MacaroonsVerifier.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/typings/tsd.d.ts" />
import Macaroon = require('./Macaroon');
export = MacaroonsVerifier;
/**
Expand Down
4 changes: 2 additions & 2 deletions lib/MacaroonsVerifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ var MacaroonsVerifier = (function () {
var caveat = caveatPackets[i];
if (caveat == null)
continue;
if (caveat.type == 5 /* cl */)
if (caveat.type == CaveatPacketType.cl)
continue;
if (!(caveat.type == 3 /* cid */ && caveatPackets[Math.min(i + 1, caveatPackets.length - 1)].type == 4 /* vid */)) {
if (!(caveat.type == CaveatPacketType.cid && caveatPackets[Math.min(i + 1, caveatPackets.length - 1)].type == CaveatPacketType.vid)) {
if (MacaroonsVerifier.containsElement(this.predicates, caveat.getValueAsText()) || this.verifiesGeneral(caveat.getValueAsText())) {
csig = CryptoTools.macaroon_hmac(csig, caveat.rawValue);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "macaroons.js",
"version": "0.3.5",
"version": "0.3.6",
"description": "Javascript implementation of Macaroons: Cookies with Contextual Caveats for Decentralized Authorization in the Cloud.",
"readmeFilename": "README.md",
"main": "index.js",
Expand Down

0 comments on commit 249ac4b

Please sign in to comment.