toCompactSerialization method
Serializes the JsonWebSignature or JsonWebEncryption to a string.
Throws an exception when object cannot be serialized to its compact form, i.e. when the JsonWebSignature has multiple signatures or the JsonWebEncryption has multiple recipients.
Implementation
@override
String toCompactSerialization() {
if (recipients.length != 1) {
throw StateError(
'Compact serialization does not support multiple signatures');
}
var signature = recipients.first;
if (signature.unprotectedHeader != null) {
throw StateError(
'Compact serialization does not support unprotected header parameters');
}
return '${signature.protectedHeader!.toBase64EncodedString()}.${encodeBase64EncodedBytes(data)}.'
'${encodeBase64EncodedBytes(signature.data)}';
}