validateKey method

void validateKey()
inherited

Validates the AtKey

Throws InvalidAtKeyException when the following conditions are met

  • When metadata.isCached is set to true on a local key

  • When metadata.isPublic is set to true on a local key

  • When sharedWith is populated on a local key

  • When metadata.isPublic is set to true on a shared key

  • When AtKey.key is set to null or empty

  • When AtKey.key contains @ or : characters

Implementation

void validateKey() {
  if (atKey.metadata.isCached == true && atKey.isLocal == true) {
    throw InvalidAtKeyException('Cached key cannot be a local key');
  }
  if (atKey.isLocal == true &&
      (atKey.metadata.isPublic == true ||
          atKey.sharedWith.isNotNullOrEmpty)) {
    throw InvalidAtKeyException(
        'When isLocal is set to true, cannot set isPublic to true or set a non-null sharedWith');
  }
  if (atKey.metadata.isPublic == true && atKey.sharedWith.isNotNullOrEmpty) {
    throw InvalidAtKeyException(
        'When isPublic is set to true, sharedWith cannot be populated');
  }
  if (atKey.key.isNullOrEmpty) {
    throw InvalidAtKeyException('Key cannot be null or empty');
  }
}