Skip to content

Commit

Permalink
Prepare sealer for type encoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhanson committed Feb 11, 2021
1 parent 63c4957 commit 42a1eb0
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions lib/sealer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ Sealer.prototype.seal = function(claims, recipient, options, cb) {
}
options || {};

function sealed(err, token) {
if (err) { return cb(err); }
return cb(null, token);
}

// TODO: Figure out the expanded API for keyring. Right now it is is
// `recipient, cb`, where recipient is a hostname (undefined meaning "self").
Expand All @@ -46,56 +42,66 @@ Sealer.prototype.seal = function(claims, recipient, options, cb) {

var self = this;

var confidential = options.confidential !== undefined ? options.confidential : true;

var query = {
usage: confidential ? 'encrypt' : 'sign',
// TODO: Implement way to pass in negotiated algorithms?
//signingAlgorithms: options.signingAlgorithms
//algorithms: confidential ? ENCRYPTION_ALGORITHMS : SIGNING_ALGORITHMS
}
function encoded(err, tclaims) {

this._keyring.get(recipient, query, function(err, key, sender) {
function addressed(err, aclaims, header) {
function sealed(err, token) {
if (err) { return cb(err); }
return cb(null, token);
}

var confidential = options.confidential !== undefined ? options.confidential : true;

var query = {
usage: confidential ? 'encrypt' : 'sign',
// TODO: Implement way to pass in negotiated algorithms?
//signingAlgorithms: options.signingAlgorithms
//algorithms: confidential ? ENCRYPTION_ALGORITHMS : SIGNING_ALGORITHMS
}

self._keyring.get(recipient, query, function(err, key, sender) {
function addressed(err, aclaims, header) {
if (err) { return cb(err); }

aclaims = aclaims || {};
header = header || {};
merge(claims, aclaims);
aclaims = aclaims || {};
header = header || {};
merge(claims, aclaims);

function sealed(err, token) {
if (err) { return cb(err); }
return cb(null, token);
function sealed(err, token) {
if (err) { return cb(err); }
return cb(null, token);
}

var arity = self._type.seal.length;
switch (arity) {
case 5:
return self._type.seal(claims, header, key, options, sealed);
case 4:
return self._type.seal(claims, key, options, sealed);
case 3:
return self._type.seal(claims, key, sealed);
}
}

var arity = self._type.seal.length;
//console.log(self._type)

// can't do address, thus not federatable. only for "internal" tokens
if (!self._dialect || !self._dialect.address) { return addressed(); }

var arity = self._dialect.address.length;
switch (arity) {
case 5:
return self._type.seal(claims, header, key, options, sealed);
case 4:
return self._type.seal(claims, key, options, sealed);
return self._dialect.address(recipient, sender, options, addressed);
case 3:
return self._type.seal(claims, key, sealed);
return addressed(null, self._dialect.address(recipient, sender, options));
case 2:
return addressed(null, self._dialect.address(recipient, sender));
case 1:
return addressed(null, self._dialect.address(recipient));
}
}

//console.log(self._type)

// can't do address, thus not federatable. only for "internal" tokens
if (!self._dialect || !self._dialect.address) { return addressed(); }

var arity = self._dialect.address.length;
switch (arity) {
case 4:
return self._dialect.address(recipient, sender, options, addressed);
case 3:
return addressed(null, self._dialect.address(recipient, sender, options));
case 2:
return addressed(null, self._dialect.address(recipient, sender));
case 1:
return addressed(null, self._dialect.address(recipient));
}
});
});
}

encoded();
};


Expand Down

0 comments on commit 42a1eb0

Please sign in to comment.