mirror of
https://github.com/danbulant/jose
synced 2026-05-25 04:51:47 +00:00
23 lines
449 B
JavaScript
23 lines
449 B
JavaScript
const { TODO } = require('../errors')
|
|
|
|
function detect (input) {
|
|
if (typeof input === 'string') {
|
|
return 'compact'
|
|
}
|
|
|
|
if ('encrypted_key' in input) {
|
|
return 'flattened'
|
|
}
|
|
|
|
if ('recipients' in input && 'ciphertext' in input && Array.isArray(input.recipients)) {
|
|
if (input.signatures.every(s => 'encrypted_key' in s)) {
|
|
return 'general'
|
|
}
|
|
}
|
|
|
|
throw new TODO('invalid serialization')
|
|
}
|
|
|
|
module.exports = {
|
|
detect
|
|
}
|