jose/lib/jwe/serializers.js
2019-02-09 19:26:02 +01:00

20 lines
410 B
JavaScript

const { TODO } = require('../errors')
function detect (input) {
if (typeof input === 'string') {
return 'compact'
}
if ('recipients' in input && 'ciphertext' in input && Array.isArray(input.recipients)) {
if (input.recipients.every(s => 'encrypted_key' in s)) {
return 'general'
}
throw new TODO('invalid serialization')
}
return 'flattened'
}
module.exports = {
detect
}