doValidate method

  1. @override
ValidationResult doValidate()
override

Implementation

@override
ValidationResult doValidate() {
  // Ownership rules:
  // ------------------
  // Rule 1: For a self key if sharedWith is present it should be same as the @sign
  // Rule 2: For a shared key sharedWith should be different from the current @sign

  if ((type == KeyType.selfKey) &&
      sharedWith.isNotEmpty &&
      owner != sharedWith) {
    return ValidationResult(
        'For a self key owner $owner should be same as with whom it is shared with $sharedWith.');
  }
  if (type == KeyType.sharedKey && sharedWith.isEmpty) {
    return ValidationResult(
        'Shared with cannot be null for a shared key $sharedWith');
  }
  if (type == KeyType.sharedKey && owner == sharedWith) {
    return ValidationResult(
        'For a shared key owner $owner should not be same as with whom it is shared with $sharedWith.');
  }
  return ValidationResult.noFailure();
}