getPayloadFor method

  1. @override
List<int>? getPayloadFor(
  1. JsonWebKey? key,
  2. JoseHeader header,
  3. JoseRecipient recipient
)
override

Implementation

@override
List<int>? getPayloadFor(
  JsonWebKey? key,
  JoseHeader header,
  JoseRecipient recipient,
) {
  if (header.algorithm == 'none') {
    return key == null && recipient.data.isEmpty ? this.data : null;
  }

  if (key == null) {
    return null;
  }

  // verify header
  var encodedHeader = recipient.protectedHeader!.toBase64EncodedString();
  var encodedPayload = encodeBase64EncodedBytes(this.data);
  var data = convert.utf8.encode('$encodedHeader.$encodedPayload');

  return key.verify(data, recipient.data, algorithm: header.algorithm)
      ? this.data
      : null;
}