Skip to content

Commit 249ac4b

Browse files
committed
release new version 0.3.6
1 parent 560afd1 commit 249ac4b

13 files changed

+35
-148
lines changed

lib/Base64Tools.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
export = Base64Tools;
33
declare class Base64Tools {
44
private static BASE64_PADDING;

lib/BufferTools.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
export = BufferTools;
33
declare class BufferTools {
44
static equals(a: Buffer, b: Buffer): boolean;

lib/CaveatPacket.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ var CaveatPacket = (function () {
3636
};
3737
CaveatPacket.prototype.getValueAsText = function () {
3838
if (this.valueAsText == null) {
39-
this.valueAsText = (this.type == 4 /* vid */) ? Base64Tools.encodeBase64UrlSafe(this.rawValue.toString('base64')) : this.rawValue.toString(MacaroonsContants.IDENTIFIER_CHARSET);
39+
this.valueAsText = (this.type == CaveatPacketType.vid)
40+
? Base64Tools.encodeBase64UrlSafe(this.rawValue.toString('base64'))
41+
: this.rawValue.toString(MacaroonsContants.IDENTIFIER_CHARSET);
4042
}
4143
return this.valueAsText;
4244
};

lib/CryptoTools.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
import ThirdPartyPacket = require('./ThirdPartyPacket');
33
export = CryptoTools;
44
declare class CryptoTools {

lib/Macaroon.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ var Macaroon = (function () {
2424
return MacaroonsSerializer.serialize(this);
2525
};
2626
Macaroon.prototype.inspect = function () {
27-
return this.createKeyValuePacket(0 /* location */, this.location) + this.createKeyValuePacket(1 /* identifier */, this.identifier) + this.createCaveatsPackets(this.caveatPackets) + this.createKeyValuePacket(2 /* signature */, this.signature);
27+
return this.createKeyValuePacket(CaveatPacketType.location, this.location)
28+
+ this.createKeyValuePacket(CaveatPacketType.identifier, this.identifier)
29+
+ this.createCaveatsPackets(this.caveatPackets)
30+
+ this.createKeyValuePacket(CaveatPacketType.signature, this.signature);
2831
};
2932
Macaroon.prototype.createKeyValuePacket = function (type, value) {
3033
return value != null ? CaveatPacketType[type] + MacaroonsContants.KEY_VALUE_SEPARATOR_STR + value + MacaroonsContants.LINE_SEPARATOR_STR : "";

lib/MacaroonsBuilder.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
import Macaroon = require('./Macaroon');
33
export = MacaroonsBuilder;
44
/**

lib/MacaroonsBuilder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var MacaroonsBuilder = (function () {
7373
throw new Error("Too many caveats. There are max. " + MacaroonsConstants.MACAROON_MAX_CAVEATS + " caveats allowed.");
7474
}
7575
var signature = CryptoTools.macaroon_hmac(this.macaroon.signatureBuffer, caveatBuffer);
76-
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(3 /* cid */, caveatBuffer));
76+
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(CaveatPacketType.cid, caveatBuffer));
7777
this.macaroon = new Macaroon(this.macaroon.location, this.macaroon.identifier, signature, caveatsExtended);
7878
}
7979
return this;
@@ -93,7 +93,7 @@ var MacaroonsBuilder = (function () {
9393
}
9494
var thirdPartyPacket = CryptoTools.macaroon_add_third_party_caveat_raw(this.macaroon.signatureBuffer, secret, identifier);
9595
var hash = thirdPartyPacket.signature;
96-
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(3 /* cid */, identifier), new CaveatPacket(4 /* vid */, thirdPartyPacket.vid_data), new CaveatPacket(5 /* cl */, location));
96+
var caveatsExtended = this.macaroon.caveatPackets.concat(new CaveatPacket(CaveatPacketType.cid, identifier), new CaveatPacket(CaveatPacketType.vid, thirdPartyPacket.vid_data), new CaveatPacket(CaveatPacketType.cl, location));
9797
this.macaroon = new Macaroon(this.macaroon.location, this.macaroon.identifier, hash, caveatsExtended);
9898
return this;
9999
};

lib/MacaroonsDeSerializer.js

Lines changed: 15 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ var MacaroonsDeSerializer = (function () {
4545
}
4646
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.CID_BYTES)) {
4747
s = MacaroonsDeSerializer.parsePacket(packet, MacaroonsConstants.CID_BYTES);
48-
caveats.push(new CaveatPacket(3 /* cid */, s));
48+
caveats.push(new CaveatPacket(CaveatPacketType.cid, s));
4949
}
5050
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.CL_BYTES)) {
5151
s = MacaroonsDeSerializer.parsePacket(packet, MacaroonsConstants.CL_BYTES);
52-
caveats.push(new CaveatPacket(5 /* cl */, s));
52+
caveats.push(new CaveatPacket(CaveatPacketType.cl, s));
5353
}
5454
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.VID_BYTES)) {
5555
raw = MacaroonsDeSerializer.parseRawPacket(packet, MacaroonsConstants.VID_BYTES);
56-
caveats.push(new CaveatPacket(4 /* vid */, raw));
56+
caveats.push(new CaveatPacket(CaveatPacketType.vid, raw));
5757
}
5858
else if (MacaroonsDeSerializer.bytesStartWith(packet.data, MacaroonsConstants.SIGNATURE_BYTES)) {
5959
signature = MacaroonsDeSerializer.parseSignature(packet, MacaroonsConstants.SIGNATURE_BYTES);
@@ -132,7 +132,10 @@ var StatefulPacketReader = (function () {
132132
return -1;
133133
};
134134
StatefulPacketReader.prototype.readPacketHeader = function () {
135-
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++]];
135+
return (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 12)
136+
| (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 8)
137+
| (StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]] << 4)
138+
| StatefulPacketReader.HEX_ALPHABET[this.buffer[this.seekIndex++]];
136139
};
137140
StatefulPacketReader.prototype.isPacketHeaderAvailable = function () {
138141
return this.seekIndex <= (this.buffer.length - MacaroonsConstants.PACKET_PREFIX_LENGTH);
@@ -141,135 +144,14 @@ var StatefulPacketReader = (function () {
141144
return !(this.seekIndex < this.buffer.length);
142145
};
143146
StatefulPacketReader.HEX_ALPHABET = [
144-
0,
145-
0,
146-
0,
147-
0,
148-
0,
149-
0,
150-
0,
151-
0,
152-
0,
153-
0,
154-
0,
155-
0,
156-
0,
157-
0,
158-
0,
159-
0,
160-
0,
161-
0,
162-
0,
163-
0,
164-
0,
165-
0,
166-
0,
167-
0,
168-
0,
169-
0,
170-
0,
171-
0,
172-
0,
173-
0,
174-
0,
175-
0,
176-
0,
177-
0,
178-
0,
179-
0,
180-
0,
181-
0,
182-
0,
183-
0,
184-
0,
185-
0,
186-
0,
187-
0,
188-
0,
189-
0,
190-
0,
191-
0,
192-
0,
193-
1,
194-
2,
195-
3,
196-
4,
197-
5,
198-
6,
199-
7,
200-
8,
201-
9,
202-
0,
203-
0,
204-
0,
205-
0,
206-
0,
207-
0,
208-
0,
209-
10,
210-
11,
211-
12,
212-
13,
213-
14,
214-
15,
215-
0,
216-
0,
217-
0,
218-
0,
219-
0,
220-
0,
221-
0,
222-
0,
223-
0,
224-
0,
225-
0,
226-
0,
227-
0,
228-
0,
229-
0,
230-
0,
231-
0,
232-
0,
233-
0,
234-
0,
235-
0,
236-
0,
237-
0,
238-
0,
239-
0,
240-
0,
241-
10,
242-
11,
243-
12,
244-
13,
245-
14,
246-
15,
247-
0,
248-
0,
249-
0,
250-
0,
251-
0,
252-
0,
253-
0,
254-
0,
255-
0,
256-
0,
257-
0,
258-
0,
259-
0,
260-
0,
261-
0,
262-
0,
263-
0,
264-
0,
265-
0,
266-
0,
267-
0,
268-
0,
269-
0,
270-
0,
271-
0
272-
];
147+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
148+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
149+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
150+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0,
151+
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153+
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0,
154+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
273155
return StatefulPacketReader;
274156
})();
275157
module.exports = MacaroonsDeSerializer;

lib/MacaroonsSerializer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
import Macaroon = require('./Macaroon');
33
export = MacaroonsSerializer;
44
declare class MacaroonsSerializer {

lib/MacaroonsSerializer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ var MacaroonsSerializer = (function () {
2121
}
2222
MacaroonsSerializer.serialize = function (macaroon) {
2323
var packets = [];
24-
packets.push(MacaroonsSerializer.serialize_packet(0 /* location */, macaroon.location), MacaroonsSerializer.serialize_packet(1 /* identifier */, macaroon.identifier));
24+
packets.push(MacaroonsSerializer.serialize_packet(CaveatPacketType.location, macaroon.location), MacaroonsSerializer.serialize_packet(CaveatPacketType.identifier, macaroon.identifier));
2525
packets = packets.concat(macaroon.caveatPackets.map(function (caveatPacket) {
2626
return MacaroonsSerializer.serialize_packet_buf(caveatPacket.type, caveatPacket.rawValue);
2727
}));
28-
packets.push(MacaroonsSerializer.serialize_packet_buf(2 /* signature */, macaroon.signatureBuffer));
28+
packets.push(MacaroonsSerializer.serialize_packet_buf(CaveatPacketType.signature, macaroon.signatureBuffer));
2929
var base64 = MacaroonsSerializer.flattenByteArray(packets).toString("base64");
3030
return Base64Tools.encodeBase64UrlSafe(base64);
3131
};

lib/MacaroonsVerifier.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="../../typings/tsd.d.ts" />
1+
/// <reference path="../../src/typings/tsd.d.ts" />
22
import Macaroon = require('./Macaroon');
33
export = MacaroonsVerifier;
44
/**

lib/MacaroonsVerifier.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ var MacaroonsVerifier = (function () {
105105
var caveat = caveatPackets[i];
106106
if (caveat == null)
107107
continue;
108-
if (caveat.type == 5 /* cl */)
108+
if (caveat.type == CaveatPacketType.cl)
109109
continue;
110-
if (!(caveat.type == 3 /* cid */ && caveatPackets[Math.min(i + 1, caveatPackets.length - 1)].type == 4 /* vid */)) {
110+
if (!(caveat.type == CaveatPacketType.cid && caveatPackets[Math.min(i + 1, caveatPackets.length - 1)].type == CaveatPacketType.vid)) {
111111
if (MacaroonsVerifier.containsElement(this.predicates, caveat.getValueAsText()) || this.verifiesGeneral(caveat.getValueAsText())) {
112112
csig = CryptoTools.macaroon_hmac(csig, caveat.rawValue);
113113
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macaroons.js",
3-
"version": "0.3.5",
3+
"version": "0.3.6",
44
"description": "Javascript implementation of Macaroons: Cookies with Contextual Caveats for Decentralized Authorization in the Cloud.",
55
"readmeFilename": "README.md",
66
"main": "index.js",

0 commit comments

Comments
 (0)