base64UrlDecodeStrict function

List<int> base64UrlDecodeStrict(
  1. String input
)

Strict base64url decoding (padding optional). Throws FormatException for anything else.

Implementation

List<int> base64UrlDecodeStrict(String input) {
  final s = input.replaceAll(RegExp(r'=+$'), '');
  if (!_b64url.hasMatch(s) || s.length % 4 == 1) throw const FormatException('Malformed base64url value.');
  return base64Url.decode(s + '=' * ((4 - s.length % 4) % 4));
}