generate method

String generate([
  1. String? url
])

Implementation

String generate([String? url]) {
  var start = 0;
  var expiration = _expiration;
  if (_expiration == 0) {
    if (_duration > 0) {
      if (startTime > 0) {
        start = startTime;
      } else {
        start =
            (DateTime.now().toUtc().millisecondsSinceEpoch / 1000).round();
      }
      expiration = start + _duration;
    } else {
      throw ArgumentError('Must provide either expiration or duration');
    }
  }
  List tokenParts = <String>[];
  if (ip != null) {
    tokenParts.add('ip=$ip');
  }
  if (startTime > 0) {
    tokenParts.add('st=$startTime');
  }
  tokenParts.add('exp=$expiration');
  if (acl != null) {
    var uri = Uri.encodeComponent(acl!).toLowerCase();
    tokenParts.add('acl=$uri'); // need to encode this String
  }
  var toSign = tokenParts;
  if (url != null && acl == null) {
    toSign.add('url=$url');
  }
  var auth = digest(toSign.join("~"));
  tokenParts.add("hmac=$auth");
  return "${_tokenName!}=${tokenParts.join("~")}";
}